//@revisions: noopt opt //@[noopt] build-fail //@[opt] compile-flags: -O //FIXME: `opt` revision currently does not stop with an error due to //. //@[opt] build-pass //! 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 Fail(T); impl Fail { const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::::C` failed } // This function is not actually called, but is mentioned implicitly as destructor in dead code in a // function that is called. Make sure we still find this error. impl Drop for Fail { fn drop(&mut self) { let _ = Fail::::C; } } #[inline(never)] fn called(x: T) { if false { let v = Fail(x); drop(v); // move `v` away (and it then gets dropped there so build still fails) } } pub fn main() { called::(0); }