@@ -19,7 +19,7 @@ extern crate tracing;
19
19
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
20
20
use rustc_data_structures:: graph:: dominators:: Dominators ;
21
21
use rustc_data_structures:: vec_map:: VecMap ;
22
- use rustc_errors:: { Diagnostic , DiagnosticBuilder , ErrorGuaranteed } ;
22
+ use rustc_errors:: { Diagnostic , DiagnosticBuilder } ;
23
23
use rustc_hir as hir;
24
24
use rustc_hir:: def_id:: LocalDefId ;
25
25
use rustc_index:: bit_set:: ChunkedBitSet ;
@@ -192,13 +192,13 @@ fn do_mir_borrowck<'tcx>(
192
192
}
193
193
}
194
194
195
- let mut errors = error:: BorrowckErrors :: new ( ) ;
195
+ let mut errors = error:: BorrowckErrors :: new ( infcx . tcx ) ;
196
196
197
197
// Gather the upvars of a closure, if any.
198
198
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 ) ;
202
202
}
203
203
let upvars: Vec < _ > = tables
204
204
. closure_min_captures_flattened ( def. did )
@@ -2260,6 +2260,7 @@ mod error {
2260
2260
use super :: * ;
2261
2261
2262
2262
pub struct BorrowckErrors < ' tcx > {
2263
+ tcx : TyCtxt < ' tcx > ,
2263
2264
/// This field keeps track of move errors that are to be reported for given move indices.
2264
2265
///
2265
2266
/// There are situations where many errors can be reported for a single move out (see #53807)
@@ -2282,28 +2283,33 @@ mod error {
2282
2283
tainted_by_errors : Option < ErrorGuaranteed > ,
2283
2284
}
2284
2285
2285
- impl BorrowckErrors < ' _ > {
2286
- pub fn new ( ) -> Self {
2286
+ impl < ' tcx > BorrowckErrors < ' tcx > {
2287
+ pub fn new ( tcx : TyCtxt < ' tcx > ) -> Self {
2287
2288
BorrowckErrors {
2289
+ tcx,
2288
2290
buffered_move_errors : BTreeMap :: new ( ) ,
2289
2291
buffered : Default :: default ( ) ,
2290
2292
tainted_by_errors : None ,
2291
2293
}
2292
2294
}
2293
2295
2294
- // FIXME(eddyb) this is a suboptimal API because `tainted_by_errors` is
2295
- // set before any emission actually happens (weakening the guarantee).
2296
2296
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
+ }
2298
2304
t. buffer ( & mut self . buffered ) ;
2299
2305
}
2300
2306
2301
2307
pub fn buffer_non_error_diag ( & mut self , t : DiagnosticBuilder < ' _ , ( ) > ) {
2302
2308
t. buffer ( & mut self . buffered ) ;
2303
2309
}
2304
2310
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 ) ;
2307
2313
}
2308
2314
}
2309
2315
0 commit comments