Const-eval errors in dead functions are optimization-dependent #107503
Closed
Description
I tried this code: [playground]
#![feature(inline_const)]
pub fn cause_late_error<T>() {
const {
panic!()
};
}
fn main() {
let a = 1;
let b = 2;
if a + b == 5 {
cause_late_error::<()>();
}
}
I expected to see this happen:
error[E0080]: evaluation of `cause_late_error::<()>::{constant#0}` failed
--> src/main.rs:7:9
|
7 | panic!()
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', src/main.rs:7:9
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
note: the above error was encountered while instantiating `fn cause_late_error::<()>`
--> src/main.rs:13:9
|
13 | cause_late_error::<()>();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Instead, this happened: it compiled without any warnings.
Meta
Playground nightly, 1.69.0-nightly (2023-01-30 001a77f)
Related
- dead-code optimize
if const { expr }
even in opt-level=0 #85836 - Stabilise inline_const #104087
- unused function is not monomorphized, so post-mono lints do not show up (in particular affects associated and inline consts) #106617
Potential fix: