@@ -14,6 +14,7 @@ use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
1414use rustc:: ty:: layout:: { self , LayoutOf , VariantIdx } ;
1515use rustc:: ty:: subst:: Subst ;
1616use rustc:: traits:: Reveal ;
17+ use rustc:: util:: common:: ErrorReported ;
1718use rustc_data_structures:: fx:: FxHashMap ;
1819
1920use 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