@@ -192,13 +192,13 @@ fn do_mir_borrowck<'tcx>(
192192 }
193193 }
194194
195- let mut errors = error:: BorrowckErrors :: new ( ) ;
195+ let mut errors = error:: BorrowckErrors :: new ( infcx . tcx ) ;
196196
197197 // Gather the upvars of a closure, if any.
198198 let tables = tcx. typeck_opt_const_arg ( def) ;
199- if let Some ( ErrorGuaranteed { .. } ) = tables. tainted_by_errors {
199+ if let Some ( e ) = tables. tainted_by_errors {
200200 infcx. set_tainted_by_errors ( ) ;
201- errors. set_tainted_by_errors ( ) ;
201+ errors. set_tainted_by_errors ( e ) ;
202202 }
203203 let upvars: Vec < _ > = tables
204204 . closure_min_captures_flattened ( def. did )
@@ -2260,6 +2260,7 @@ mod error {
22602260 use super :: * ;
22612261
22622262 pub struct BorrowckErrors < ' tcx > {
2263+ tcx : TyCtxt < ' tcx > ,
22632264 /// This field keeps track of move errors that are to be reported for given move indices.
22642265 ///
22652266 /// There are situations where many errors can be reported for a single move out (see #53807)
@@ -2282,28 +2283,29 @@ mod error {
22822283 tainted_by_errors : Option < ErrorGuaranteed > ,
22832284 }
22842285
2285- impl BorrowckErrors < ' _ > {
2286- pub fn new ( ) -> Self {
2286+ impl < ' tcx > BorrowckErrors < ' tcx > {
2287+ pub fn new ( tcx : TyCtxt < ' tcx > ) -> Self {
22872288 BorrowckErrors {
2289+ tcx,
22882290 buffered_move_errors : BTreeMap :: new ( ) ,
22892291 buffered : Default :: default ( ) ,
22902292 tainted_by_errors : None ,
22912293 }
22922294 }
22932295
2294- // FIXME(eddyb) this is a suboptimal API because `tainted_by_errors` is
2295- // set before any emission actually happens (weakening the guarantee).
22962296 pub fn buffer_error ( & mut self , t : DiagnosticBuilder < ' _ , ErrorGuaranteed > ) {
2297- self . tainted_by_errors = Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
2297+ self . tainted_by_errors = Some (
2298+ self . tcx . sess . delay_span_bug ( t. span . clone ( ) , "diagnostic buffered but not emitted" ) ,
2299+ ) ;
22982300 t. buffer ( & mut self . buffered ) ;
22992301 }
23002302
23012303 pub fn buffer_non_error_diag ( & mut self , t : DiagnosticBuilder < ' _ , ( ) > ) {
23022304 t. buffer ( & mut self . buffered ) ;
23032305 }
23042306
2305- pub fn set_tainted_by_errors ( & mut self ) {
2306- self . tainted_by_errors = Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
2307+ pub fn set_tainted_by_errors ( & mut self , e : ErrorGuaranteed ) {
2308+ self . tainted_by_errors = Some ( e ) ;
23072309 }
23082310 }
23092311
0 commit comments