Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for const-eval error in dead code during monomorphization #116444

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/ui/consts/const-eval/unused-broken-const-late.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// build-fail
// compile-flags: -O
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)

struct PrintName<T>(T);
impl<T> PrintName<T> {
const VOID: () = panic!(); //~ERROR evaluation of `PrintName::<i32>::VOID` failed
}

fn no_codegen<T>() {
// Any function that is called is guaranteed to have all consts that syntactically
// appear in its body evaluated, even if they only appear in dead code.
if false {
let _ = PrintName::<T>::VOID;
}
}
pub fn main() {
no_codegen::<i32>();
}
11 changes: 11 additions & 0 deletions tests/ui/consts/const-eval/unused-broken-const-late.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0080]: evaluation of `PrintName::<i32>::VOID` failed
--> $DIR/unused-broken-const-late.rs:8:22
|
LL | const VOID: () = panic!();
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/unused-broken-const-late.rs:8:22
|
= 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)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
Loading