Auto merge of #71518 - felix91gr:const_prop_bugfix_just_block_prop, r=wesleywiser

Const-prop bugfix: only add propagation inside own block for user variables

A testing spinoff of #71298. This one only adds the const-prop for locals that are user variables.
This commit is contained in:
bors 2020-04-29 03:04:46 +00:00
commit 92019986aa
22 changed files with 818 additions and 41 deletions

View file

@ -0,0 +1,24 @@
// build-fail
fn main() {
divide_by_zero();
mod_by_zero();
oob_error_for_slices();
}
fn divide_by_zero() {
let y = 0;
let _z = 1 / y; //~ ERROR this operation will panic at runtime [unconditional_panic]
}
fn mod_by_zero() {
let y = 0;
let _z = 1 % y; //~ ERROR this operation will panic at runtime [unconditional_panic]
}
fn oob_error_for_slices() {
let a: *const [_] = &[1, 2, 3];
unsafe {
let _b = (*a)[3]; //~ ERROR this operation will panic at runtime [unconditional_panic]
}
}

View file

@ -0,0 +1,22 @@
error: this operation will panic at runtime
--> $DIR/mir_detects_invalid_ops.rs:11:14
|
LL | let _z = 1 / y;
| ^^^^^ attempt to divide by zero
|
= note: `#[deny(unconditional_panic)]` on by default
error: this operation will panic at runtime
--> $DIR/mir_detects_invalid_ops.rs:16:14
|
LL | let _z = 1 % y;
| ^^^^^ attempt to calculate the remainder with a divisor of zero
error: this operation will panic at runtime
--> $DIR/mir_detects_invalid_ops.rs:22:18
|
LL | let _b = (*a)[3];
| ^^^^^^^ index out of bounds: the len is 3 but the index is 3
error: aborting due to 3 previous errors