Closed
Description
I found a surprising behavior of constant evaluation and I'm not sure if it's intended.
I feel this is a small usability issue with panics in const context for implementing
compile time assertions.
I tried this code(playground):
trait ConstPanic {
const EVAL: ();
}
impl ConstPanic for i32 {
// Does not seem to be evaluated unless used.
// Program compiles, unexpectedly.
const EVAL: () = panic!("oh no!");
}
fn main() {
// Uncommenting the following gives the compile time panic
// I expect to see. It also gives "warning: path statement with no effect"
// In this case, it clearly has a compile time effect.
//i32::EVAL;
}
I expected to see this happen: The program fails to compile
Instead, this happened: The program compiles and runs.
Meta
rustc --version --verbose
:
rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-apple-darwin
release: 1.57.0
LLVM version: 13.0.0