Skip to content

Commit d51b41c

Browse files
committed
add test for const-eval error in dead code during monomorphization
1 parent 5236c8e commit d51b41c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// build-fail
2+
//! Make sure we detect erroneous constants post-monomorphization even when they are unused.
3+
//! This is crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
4+
5+
struct PrintName<T>(T);
6+
impl<T> PrintName<T> {
7+
const VOID: () = panic!(); //~ERROR evaluation of `PrintName::<i32>::VOID` failed
8+
}
9+
10+
fn no_codegen<T>() {
11+
// Any function that is called is guaranteed to have all consts that syntactically
12+
// appear in its body evaluated, even if they only appear in dead code.
13+
if false {
14+
let _ = PrintName::<T>::VOID;
15+
}
16+
}
17+
pub fn main() {
18+
no_codegen::<i32>(); //~ encountered
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0080]: evaluation of `PrintName::<i32>::VOID` failed
2+
--> $DIR/unused-broken-const-late.rs:7:22
3+
|
4+
LL | const VOID: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/unused-broken-const-late.rs:7:22
6+
|
7+
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
note: the above error was encountered while instantiating `fn no_codegen::<i32>`
10+
--> $DIR/unused-broken-const-late.rs:18:5
11+
|
12+
LL | no_codegen::<i32>();
13+
| ^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)