2020-05-24 14:37:09 -05:00
|
|
|
//! Tests that assignment in both branches of an `if` are eliminated.
|
2022-04-24 16:34:24 -05:00
|
|
|
// unit-test: DestinationPropagation
|
2020-05-24 14:37:09 -05:00
|
|
|
fn val() -> i32 {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cond() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2022-04-24 16:34:24 -05:00
|
|
|
// EMIT_MIR branch.foo.DestinationPropagation.diff
|
|
|
|
fn foo() -> i32 {
|
2020-05-24 14:37:09 -05:00
|
|
|
let x = val();
|
|
|
|
|
|
|
|
let y = if cond() {
|
|
|
|
x
|
|
|
|
} else {
|
|
|
|
val();
|
|
|
|
x
|
|
|
|
};
|
2022-04-24 16:34:24 -05:00
|
|
|
|
|
|
|
y
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
foo();
|
2020-05-24 14:37:09 -05:00
|
|
|
}
|