@@ -14,6 +14,7 @@ use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
14
14
use rustc:: ty:: layout:: { self , LayoutOf , VariantIdx } ;
15
15
use rustc:: ty:: subst:: Subst ;
16
16
use rustc:: traits:: Reveal ;
17
+ use rustc:: util:: common:: ErrorReported ;
17
18
use rustc_data_structures:: fx:: FxHashMap ;
18
19
19
20
use syntax:: ast:: Mutability ;
@@ -641,16 +642,21 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
641
642
let err = error_to_const_error ( & ecx, error) ;
642
643
// errors in statics are always emitted as fatal errors
643
644
if tcx. is_static ( def_id) . is_some ( ) {
644
- let reported_err = err. report_as_error ( ecx. tcx ,
645
- "could not evaluate static initializer" ) ;
646
645
// Ensure that if the above error was either `TooGeneric` or `Reported`
647
646
// 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 ,
650
654
& format ! ( "static eval failure did not emit an error: {:#?}" ,
651
- reported_err) ) ;
655
+ v) ) ;
656
+ v
657
+ } ,
658
+ Err ( ErrorReported ) => ErrorHandled :: Reported ,
652
659
}
653
- reported_err
654
660
} else if def_id. is_local ( ) {
655
661
// constant defined in this crate, we can figure out a lint level!
656
662
match tcx. describe_def ( def_id) {
0 commit comments