@@ -649,15 +649,19 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
649
649
} ) . map_err ( |error| {
650
650
let stacktrace = ecx. generate_stacktrace ( None ) ;
651
651
let err = ConstEvalErr { error, stacktrace, span : ecx. tcx . span } ;
652
+ // errors in statics are always emitted as fatal errors
652
653
if tcx. is_static ( def_id) . is_some ( ) {
653
654
let err = err. report_as_error ( ecx. tcx , "could not evaluate static initializer" ) ;
655
+ // check that a static never produces `TooGeneric`
654
656
if tcx. sess . err_count ( ) == 0 {
655
657
span_bug ! ( ecx. tcx. span, "static eval failure didn't emit an error: {:#?}" , err) ;
656
658
}
657
659
err
658
660
} else if def_id. is_local ( ) {
659
661
// constant defined in this crate, we can figure out a lint level!
660
662
match tcx. describe_def ( def_id) {
663
+ // constants never produce a hard error at the definition site. Anything else is
664
+ // a backwards compatibility hazard (and will break old versions of winapi for sure)
661
665
Some ( Def :: Const ( _) ) | Some ( Def :: AssociatedConst ( _) ) => {
662
666
let node_id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
663
667
err. report_as_lint (
@@ -666,6 +670,8 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
666
670
node_id,
667
671
)
668
672
} ,
673
+ // promoting runtime code is only allowed to error if it references broken constants
674
+ // any other kind of error will be reported to the user as a deny-by-default lint
669
675
_ => if let Some ( p) = cid. promoted {
670
676
let span = tcx. optimized_mir ( def_id) . promoted [ p] . span ;
671
677
if let EvalErrorKind :: ReferencedConstant = err. error . kind {
@@ -680,6 +686,8 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
680
686
tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ,
681
687
)
682
688
}
689
+ // anything else (array lengths, enum initializers, constant patterns) are reported
690
+ // as hard errors
683
691
} else {
684
692
err. report_as_error (
685
693
ecx. tcx ,
@@ -688,7 +696,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
688
696
} ,
689
697
}
690
698
} else {
691
- // use of constant from other crate
699
+ // use of broken constant from other crate
692
700
err. report_as_error ( ecx. tcx , "could not evaluate constant" )
693
701
}
694
702
} )
0 commit comments