@@ -2,8 +2,8 @@ use super::{CompileTimeEvalContext, CompileTimeInterpreter, ConstEvalErr, Memory
2
2
use crate :: interpret:: eval_nullary_intrinsic;
3
3
use crate :: interpret:: {
4
4
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 ,
7
7
} ;
8
8
use crate :: util:: pretty:: display_allocation;
9
9
@@ -312,23 +312,17 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
312
312
let err = ConstEvalErr :: new ( & ecx, error, None ) ;
313
313
// Some CTFE errors raise just a lint, not a hard error; see
314
314
// <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 ( ) {
316
316
// (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 ( )
319
320
} else {
320
321
// use of broken constant from other crate: always an error
321
- false
322
+ true
322
323
} ;
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 {
332
326
let msg = if is_static {
333
327
Cow :: from ( "could not evaluate static initializer" )
334
328
} else {
@@ -346,6 +340,14 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
346
340
} ;
347
341
348
342
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
+ ) )
349
351
}
350
352
}
351
353
Ok ( mplace) => {
0 commit comments