@@ -2,8 +2,8 @@ use super::{CompileTimeEvalContext, CompileTimeInterpreter, ConstEvalErr, Memory
22use crate :: interpret:: eval_nullary_intrinsic;
33use crate :: interpret:: {
44 intern_const_alloc_recursive, Allocation , ConstAlloc , ConstValue , CtfeValidationMode , GlobalId ,
5- Immediate , InternKind , InterpCx , InterpError , InterpResult , MPlaceTy , MemoryKind , OpTy ,
6- RefTracking , Scalar , ScalarMaybeUninit , StackPopCleanup ,
5+ Immediate , InternKind , InterpCx , InterpResult , MPlaceTy , MemoryKind , OpTy , RefTracking , Scalar ,
6+ ScalarMaybeUninit , StackPopCleanup ,
77} ;
88use crate :: util:: pretty:: display_allocation;
99
@@ -312,23 +312,17 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
312312 let err = ConstEvalErr :: new ( & ecx, error, None ) ;
313313 // Some CTFE errors raise just a lint, not a hard error; see
314314 // <https://github.com/rust-lang/rust/issues/71800>.
315- let emit_as_lint = if let Some ( def) = def. as_local ( ) {
315+ let is_hard_err = if let Some ( def) = def. as_local ( ) {
316316 // (Associated) consts only emit a lint, since they might be unused.
317- matches ! ( tcx. def_kind( def. did. to_def_id( ) ) , DefKind :: Const | DefKind :: AssocConst )
318- && !matches ! ( & err. error, InterpError :: MachineStop ( err) if err. is_hard_err( ) )
317+ !matches ! ( tcx. def_kind( def. did. to_def_id( ) ) , DefKind :: Const | DefKind :: AssocConst )
318+ // check if the inner InterpError is hard
319+ || err. error . is_hard_err ( )
319320 } else {
320321 // use of broken constant from other crate: always an error
321- false
322+ true
322323 } ;
323- if emit_as_lint {
324- let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. as_local ( ) . unwrap ( ) . did ) ;
325- Err ( err. report_as_lint (
326- tcx. at ( tcx. def_span ( def. did ) ) ,
327- "any use of this value will cause an error" ,
328- hir_id,
329- Some ( err. span ) ,
330- ) )
331- } else {
324+
325+ if is_hard_err {
332326 let msg = if is_static {
333327 Cow :: from ( "could not evaluate static initializer" )
334328 } else {
@@ -346,6 +340,14 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
346340 } ;
347341
348342 Err ( err. report_as_error ( ecx. tcx . at ( ecx. cur_span ( ) ) , & msg) )
343+ } else {
344+ let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. as_local ( ) . unwrap ( ) . did ) ;
345+ Err ( err. report_as_lint (
346+ tcx. at ( tcx. def_span ( def. did ) ) ,
347+ "any use of this value will cause an error" ,
348+ hir_id,
349+ Some ( err. span ) ,
350+ ) )
349351 }
350352 }
351353 Ok ( mplace) => {
0 commit comments