|
1 | 1 | //! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations. |
2 | 2 |
|
3 | | -use rustc_errors::{Diagnostic, ErrorGuaranteed}; |
| 3 | +use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; |
4 | 4 | use rustc_hir as hir; |
5 | 5 | use rustc_hir::def_id::DefId; |
6 | 6 | use rustc_index::bit_set::BitSet; |
@@ -214,7 +214,7 @@ pub struct Checker<'mir, 'tcx> { |
214 | 214 | local_has_storage_dead: Option<BitSet<Local>>, |
215 | 215 |
|
216 | 216 | error_emitted: Option<ErrorGuaranteed>, |
217 | | - secondary_errors: Vec<Diagnostic>, |
| 217 | + secondary_errors: Vec<DiagnosticBuilder<'tcx>>, |
218 | 218 | } |
219 | 219 |
|
220 | 220 | impl<'mir, 'tcx> Deref for Checker<'mir, 'tcx> { |
@@ -272,14 +272,17 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { |
272 | 272 | } |
273 | 273 |
|
274 | 274 | // If we got through const-checking without emitting any "primary" errors, emit any |
275 | | - // "secondary" errors if they occurred. |
| 275 | + // "secondary" errors if they occurred. Otherwise, cancel the "secondary" errors. |
276 | 276 | let secondary_errors = mem::take(&mut self.secondary_errors); |
277 | 277 | if self.error_emitted.is_none() { |
278 | 278 | for error in secondary_errors { |
279 | | - self.tcx.dcx().emit_diagnostic(error); |
| 279 | + error.emit(); |
280 | 280 | } |
281 | 281 | } else { |
282 | 282 | assert!(self.tcx.dcx().has_errors().is_some()); |
| 283 | + for error in secondary_errors { |
| 284 | + error.cancel(); |
| 285 | + } |
283 | 286 | } |
284 | 287 | } |
285 | 288 |
|
@@ -347,7 +350,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { |
347 | 350 | self.error_emitted = Some(reported); |
348 | 351 | } |
349 | 352 |
|
350 | | - ops::DiagnosticImportance::Secondary => err.buffer(&mut self.secondary_errors), |
| 353 | + ops::DiagnosticImportance::Secondary => self.secondary_errors.push(err), |
351 | 354 | } |
352 | 355 | } |
353 | 356 |
|
|
0 commit comments