Open
Description
Not sure if this is a bug, but I'd post it anyways.
When experimenting turning off optimizations for MIR output, for example, disabling debug-assertions
in the following code, the output is confusing. The overflow checking is removed from function foo
, but not from const A
evaluation.
It is less confusing if the debug assertions are turned off in all places.
BTW, is there a way to turn off const-eval
? -Zmir-opt-level=0
is not useful.
I tried this code:
const fn foo(x: i32, y: i32) -> i32 {
x + y
}
fn main() {
const A: i32 = foo(1, 2 + 34);
assert!(A == 37);
return
}
Emitted mir for the code using
rustc test.rs --emit=mir -C debug-assertions=off
with rustc version
rustc 1.72.0-nightly (fe7454bf4 2023-06-19)
I expected to see the CheckedAdd
replaced by Add
and the assertion removed in the following code:
const A: i32 = {
let mut _0: i32;
let mut _1: i32;
let mut _2: (i32, bool);
bb0: {
StorageLive(_1);
_2 = CheckedAdd(const 2_i32, const 34_i32);
assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 34_i32) -> bb1;
}
bb1: {
_1 = move (_2.0: i32);
ConstEvalCounter;
_0 = foo(const 1_i32, move _1) -> bb2;
}
bb2: {
StorageDead(_1);
return;
}
}