Skip to content

Commit 2ea7e93

Browse files
committed
delay the bug when read immediate
1 parent 2f58193 commit 2ea7e93

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
658658
abi::Scalar::Initialized { .. }
659659
)
660660
) {
661-
span_bug!(self.cur_span(), "primitive read not possible for type: {}", op.layout().ty);
661+
self.tcx().dcx().span_delayed_bug(
662+
self.cur_span(),
663+
format!("primitive read not possible for type: {}", op.layout().ty),
664+
);
662665
}
663666
let imm = self.read_immediate_raw(op)?.right().unwrap();
664667
if matches!(*imm, Immediate::Uninit) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(generic_const_exprs)]
2+
//~^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
3+
#![feature(min_generic_const_args)]
4+
//~^ WARN the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
5+
6+
struct Checked<const N: usize, const M: usize = { N + 1 }>;
7+
//~^ ERROR evaluation of `Checked::{constant#0}` failed
8+
9+
fn main() {
10+
let _: Checked<main>;
11+
//~^ ERROR the constant `main` is not of type `usize`
12+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/eval_fn_item_in_const_arg.rs:1:12
3+
|
4+
LL | #![feature(generic_const_exprs)]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
11+
--> $DIR/eval_fn_item_in_const_arg.rs:3:12
12+
|
13+
LL | #![feature(min_generic_const_args)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
17+
18+
error[E0080]: evaluation of `Checked::{constant#0}` failed
19+
--> $DIR/eval_fn_item_in_const_arg.rs:6:51
20+
|
21+
LL | struct Checked<const N: usize, const M: usize = { N + 1 }>;
22+
| ^^^^^ using uninitialized data, but this operation requires initialized memory
23+
24+
error: the constant `main` is not of type `usize`
25+
--> $DIR/eval_fn_item_in_const_arg.rs:10:12
26+
|
27+
LL | let _: Checked<main>;
28+
| ^^^^^^^^^^^^^ expected `usize`, found fn item
29+
|
30+
note: required by a const generic parameter in `Checked`
31+
--> $DIR/eval_fn_item_in_const_arg.rs:6:16
32+
|
33+
LL | struct Checked<const N: usize, const M: usize = { N + 1 }>;
34+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Checked`
35+
36+
error: aborting due to 2 previous errors; 2 warnings emitted
37+
38+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)