Skip to content

Commit 97927da

Browse files
authored
Rollup merge of #59358 - JohnTitor:use-track-errors, r=oli-obk
Use `track_errors` instead of hand rolling Fixes #59215 r? @oli-obk
2 parents 8794e21 + 0778847 commit 97927da

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
1414
use rustc::ty::layout::{self, LayoutOf, VariantIdx};
1515
use rustc::ty::subst::Subst;
1616
use rustc::traits::Reveal;
17+
use rustc::util::common::ErrorReported;
1718
use rustc_data_structures::fx::FxHashMap;
1819

1920
use syntax::ast::Mutability;
@@ -641,16 +642,21 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
641642
let err = error_to_const_error(&ecx, error);
642643
// errors in statics are always emitted as fatal errors
643644
if tcx.is_static(def_id).is_some() {
644-
let reported_err = err.report_as_error(ecx.tcx,
645-
"could not evaluate static initializer");
646645
// Ensure that if the above error was either `TooGeneric` or `Reported`
647646
// an error must be reported.
648-
if tcx.sess.err_count() == 0 {
649-
tcx.sess.delay_span_bug(err.span,
647+
let reported_err = tcx.sess.track_errors(|| {
648+
err.report_as_error(ecx.tcx,
649+
"could not evaluate static initializer")
650+
});
651+
match reported_err {
652+
Ok(v) => {
653+
tcx.sess.delay_span_bug(err.span,
650654
&format!("static eval failure did not emit an error: {:#?}",
651-
reported_err));
655+
v));
656+
v
657+
},
658+
Err(ErrorReported) => ErrorHandled::Reported,
652659
}
653-
reported_err
654660
} else if def_id.is_local() {
655661
// constant defined in this crate, we can figure out a lint level!
656662
match tcx.describe_def(def_id) {

0 commit comments

Comments
 (0)