diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 36da9037e43d9..ac0b78231df15 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -658,7 +658,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { abi::Scalar::Initialized { .. } ) ) { - span_bug!(self.cur_span(), "primitive read not possible for type: {}", op.layout().ty); + self.tcx().dcx().span_delayed_bug( + self.cur_span(), + format!("primitive read not possible for type: {}", op.layout().ty), + ); } let imm = self.read_immediate_raw(op)?.right().unwrap(); if matches!(*imm, Immediate::Uninit) { diff --git a/tests/ui/const-generics/eval_fn_item_in_const_arg.rs b/tests/ui/const-generics/eval_fn_item_in_const_arg.rs new file mode 100644 index 0000000000000..8d472a3fea7a1 --- /dev/null +++ b/tests/ui/const-generics/eval_fn_item_in_const_arg.rs @@ -0,0 +1,12 @@ +#![feature(generic_const_exprs)] +//~^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes +#![feature(min_generic_const_args)] +//~^ WARN the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes + +struct Checked; +//~^ ERROR evaluation of `Checked::{constant#0}` failed + +fn main() { + let _: Checked
; + //~^ ERROR the constant `main` is not of type `usize` +} diff --git a/tests/ui/const-generics/eval_fn_item_in_const_arg.stderr b/tests/ui/const-generics/eval_fn_item_in_const_arg.stderr new file mode 100644 index 0000000000000..25d926895ba50 --- /dev/null +++ b/tests/ui/const-generics/eval_fn_item_in_const_arg.stderr @@ -0,0 +1,38 @@ +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/eval_fn_item_in_const_arg.rs:1:12 + | +LL | #![feature(generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76560 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/eval_fn_item_in_const_arg.rs:3:12 + | +LL | #![feature(min_generic_const_args)] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + +error[E0080]: evaluation of `Checked::{constant#0}` failed + --> $DIR/eval_fn_item_in_const_arg.rs:6:51 + | +LL | struct Checked; + | ^^^^^ using uninitialized data, but this operation requires initialized memory + +error: the constant `main` is not of type `usize` + --> $DIR/eval_fn_item_in_const_arg.rs:10:12 + | +LL | let _: Checked
; + | ^^^^^^^^^^^^^ expected `usize`, found fn item + | +note: required by a const generic parameter in `Checked` + --> $DIR/eval_fn_item_in_const_arg.rs:6:16 + | +LL | struct Checked; + | ^^^^^^^^^^^^^^ required by this const generic parameter in `Checked` + +error: aborting due to 2 previous errors; 2 warnings emitted + +For more information about this error, try `rustc --explain E0080`.