@@ -19,7 +19,7 @@ extern crate tracing;
1919use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
2020use rustc_data_structures:: graph:: dominators:: Dominators ;
2121use rustc_data_structures:: vec_map:: VecMap ;
22- use rustc_errors:: { Diagnostic , DiagnosticBuilder , ErrorGuaranteed } ;
22+ use rustc_errors:: { Diagnostic , DiagnosticBuilder } ;
2323use rustc_hir as hir;
2424use rustc_hir:: def_id:: LocalDefId ;
2525use rustc_index:: bit_set:: ChunkedBitSet ;
@@ -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 {
200- infcx. set_tainted_by_errors ( ) ;
201- errors. set_tainted_by_errors ( ) ;
199+ if let Some ( e ) = tables. tainted_by_errors {
200+ infcx. set_tainted_by_errors ( e ) ;
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,33 @@ 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+ if let None = self . tainted_by_errors {
2298+ self . tainted_by_errors = Some (
2299+ self . tcx
2300+ . sess
2301+ . delay_span_bug ( t. span . clone ( ) , "diagnostic buffered but not emitted" ) ,
2302+ )
2303+ }
22982304 t. buffer ( & mut self . buffered ) ;
22992305 }
23002306
23012307 pub fn buffer_non_error_diag ( & mut self , t : DiagnosticBuilder < ' _ , ( ) > ) {
23022308 t. buffer ( & mut self . buffered ) ;
23032309 }
23042310
2305- pub fn set_tainted_by_errors ( & mut self ) {
2306- self . tainted_by_errors = Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
2311+ pub fn set_tainted_by_errors ( & mut self , e : ErrorGuaranteed ) {
2312+ self . tainted_by_errors = Some ( e ) ;
23072313 }
23082314 }
23092315
0 commit comments