Skip to content

Commit 29c601a

Browse files
committed
Stop using DiagnosticBuilder::buffer in Checker.
This requires cancelling the "secondary" errors when they're not emitted, to prevent panics due to unconsumed `DiagnosticBuilder`s.
1 parent 2668270 commit 29c601a

File tree

1 file changed

+8
-5
lines changed
  • compiler/rustc_const_eval/src/transform/check_consts

1 file changed

+8
-5
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
22
3-
use rustc_errors::{Diagnostic, ErrorGuaranteed};
3+
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
44
use rustc_hir as hir;
55
use rustc_hir::def_id::DefId;
66
use rustc_index::bit_set::BitSet;
@@ -214,7 +214,7 @@ pub struct Checker<'mir, 'tcx> {
214214
local_has_storage_dead: Option<BitSet<Local>>,
215215

216216
error_emitted: Option<ErrorGuaranteed>,
217-
secondary_errors: Vec<Diagnostic>,
217+
secondary_errors: Vec<DiagnosticBuilder<'tcx>>,
218218
}
219219

220220
impl<'mir, 'tcx> Deref for Checker<'mir, 'tcx> {
@@ -272,14 +272,17 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
272272
}
273273

274274
// 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.
276276
let secondary_errors = mem::take(&mut self.secondary_errors);
277277
if self.error_emitted.is_none() {
278278
for error in secondary_errors {
279-
self.tcx.dcx().emit_diagnostic(error);
279+
error.emit();
280280
}
281281
} else {
282282
assert!(self.tcx.dcx().has_errors().is_some());
283+
for error in secondary_errors {
284+
error.cancel();
285+
}
283286
}
284287
}
285288

@@ -347,7 +350,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
347350
self.error_emitted = Some(reported);
348351
}
349352

350-
ops::DiagnosticImportance::Secondary => err.buffer(&mut self.secondary_errors),
353+
ops::DiagnosticImportance::Secondary => self.secondary_errors.push(err),
351354
}
352355
}
353356

0 commit comments

Comments
 (0)