@@ -615,7 +615,12 @@ pub fn const_eval_provider<'tcx>(
615
615
ty:: FnDef ( _, substs) => substs,
616
616
_ => bug ! ( "intrinsic with type {:?}" , ty) ,
617
617
} ;
618
- return Ok ( eval_nullary_intrinsic ( tcx, key. param_env , def_id, substs) ) ;
618
+ return eval_nullary_intrinsic ( tcx, key. param_env , def_id, substs)
619
+ . map_err ( |error| {
620
+ let span = tcx. def_span ( def_id) ;
621
+ let error = ConstEvalErr { error : error. kind , stacktrace : vec ! [ ] , span } ;
622
+ error. report_as_error ( tcx. at ( span) , "could not evaluate nullary intrinsic" )
623
+ } )
619
624
}
620
625
621
626
tcx. const_eval_raw ( key) . and_then ( |val| {
@@ -680,63 +685,63 @@ pub fn const_eval_raw_provider<'tcx>(
680
685
} )
681
686
} ) . map_err ( |error| {
682
687
let err = error_to_const_error ( & ecx, error) ;
683
- // errors in statics are always emitted as fatal errors
684
- if tcx. is_static ( def_id) {
685
- // Ensure that if the above error was either `TooGeneric` or `Reported`
686
- // an error must be reported.
688
+ // errors in statics are always emitted as fatal errors
689
+ if tcx. is_static ( def_id) {
690
+ // Ensure that if the above error was either `TooGeneric` or `Reported`
691
+ // an error must be reported.
687
692
let v = err. report_as_error ( ecx. tcx , "could not evaluate static initializer" ) ;
688
- tcx. sess . delay_span_bug (
689
- err. span ,
690
- & format ! ( "static eval failure did not emit an error: {:#?}" , v)
691
- ) ;
692
- v
693
- } else if def_id. is_local ( ) {
694
- // constant defined in this crate, we can figure out a lint level!
695
- match tcx. def_kind ( def_id) {
696
- // constants never produce a hard error at the definition site. Anything else is
697
- // a backwards compatibility hazard (and will break old versions of winapi for sure)
698
- //
699
- // note that validation may still cause a hard error on this very same constant,
700
- // because any code that existed before validation could not have failed validation
701
- // thus preventing such a hard error from being a backwards compatibility hazard
702
- Some ( DefKind :: Const ) | Some ( DefKind :: AssocConst ) => {
703
- let hir_id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
693
+ tcx. sess . delay_span_bug (
694
+ err. span ,
695
+ & format ! ( "static eval failure did not emit an error: {:#?}" , v)
696
+ ) ;
697
+ v
698
+ } else if def_id. is_local ( ) {
699
+ // constant defined in this crate, we can figure out a lint level!
700
+ match tcx. def_kind ( def_id) {
701
+ // constants never produce a hard error at the definition site. Anything else is
702
+ // a backwards compatibility hazard (and will break old versions of winapi for sure)
703
+ //
704
+ // note that validation may still cause a hard error on this very same constant,
705
+ // because any code that existed before validation could not have failed validation
706
+ // thus preventing such a hard error from being a backwards compatibility hazard
707
+ Some ( DefKind :: Const ) | Some ( DefKind :: AssocConst ) => {
708
+ let hir_id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
709
+ err. report_as_lint (
710
+ tcx. at ( tcx. def_span ( def_id) ) ,
711
+ "any use of this value will cause an error" ,
712
+ hir_id,
713
+ Some ( err. span ) ,
714
+ )
715
+ } ,
716
+ // promoting runtime code is only allowed to error if it references broken constants
717
+ // any other kind of error will be reported to the user as a deny-by-default lint
718
+ _ => if let Some ( p) = cid. promoted {
719
+ let span = tcx. promoted_mir ( def_id) [ p] . span ;
720
+ if let err_inval ! ( ReferencedConstant ) = err. error {
721
+ err. report_as_error (
722
+ tcx. at ( span) ,
723
+ "evaluation of constant expression failed" ,
724
+ )
725
+ } else {
704
726
err. report_as_lint (
705
- tcx. at ( tcx . def_span ( def_id ) ) ,
706
- "any use of this value will cause an error " ,
707
- hir_id ,
727
+ tcx. at ( span ) ,
728
+ "reaching this expression at runtime will panic or abort " ,
729
+ tcx . hir ( ) . as_local_hir_id ( def_id ) . unwrap ( ) ,
708
730
Some ( err. span ) ,
709
731
)
710
- } ,
711
- // promoting runtime code is only allowed to error if it references broken constants
712
- // any other kind of error will be reported to the user as a deny-by-default lint
713
- _ => if let Some ( p) = cid. promoted {
714
- let span = tcx. promoted_mir ( def_id) [ p] . span ;
715
- if let err_inval ! ( ReferencedConstant ) = err. error {
716
- err. report_as_error (
717
- tcx. at ( span) ,
718
- "evaluation of constant expression failed" ,
719
- )
720
- } else {
721
- err. report_as_lint (
722
- tcx. at ( span) ,
723
- "reaching this expression at runtime will panic or abort" ,
724
- tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ,
725
- Some ( err. span ) ,
726
- )
727
- }
728
- // anything else (array lengths, enum initializers, constant patterns) are reported
729
- // as hard errors
730
- } else {
731
- err. report_as_error (
732
+ }
733
+ // anything else (array lengths, enum initializers, constant patterns) are reported
734
+ // as hard errors
735
+ } else {
736
+ err. report_as_error (
732
737
ecx. tcx ,
733
- "evaluation of constant value failed" ,
734
- )
735
- } ,
736
- }
737
- } else {
738
- // use of broken constant from other crate
739
- err. report_as_error ( ecx. tcx , "could not evaluate constant" )
738
+ "evaluation of constant value failed" ,
739
+ )
740
+ } ,
740
741
}
742
+ } else {
743
+ // use of broken constant from other crate
744
+ err. report_as_error ( ecx. tcx , "could not evaluate constant" )
745
+ }
741
746
} )
742
747
}
0 commit comments