Files
rust/tests/ui/consts/required-consts/interpret-in-const-called-fn.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
676 B
Rust
Raw Normal View History

//@revisions: noopt opt
2024-03-18 17:54:48 +01:00
//@[noopt] compile-flags: -Copt-level=0
//@[opt] compile-flags: -O
//! Make sure we error on erroneous consts even if they are unused.
struct Fail<T>(T);
impl<T> Fail<T> {
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed
}
#[inline(never)]
const fn no_codegen<T>() {
2020-08-11 12:42:05 +02:00
if false {
2021-05-09 16:07:00 +02:00
// This bad constant is only used in dead code in a no-codegen function... and yet we still
// must make sure that the build fails.
// This relies on const-eval evaluating all `required_consts` of `const fn`.
Fail::<T>::C; //~ constant
}
}
pub static FOO: () = no_codegen::<i32>();
fn main() {
FOO
}