Skip to content

Commit 4d89031

Browse files
committed
[const-prop] Handle MIR Rvalue::Discriminant
1 parent a2e3ed5 commit 4d89031

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
436436

437437
// if this isn't a supported operation, then return None
438438
match rvalue {
439-
Rvalue::NullaryOp(NullOp::Box, _) |
440-
Rvalue::Discriminant(..) => return None,
439+
Rvalue::NullaryOp(NullOp::Box, _) => return None,
441440

442441
Rvalue::Use(_) |
443442
Rvalue::Len(_) |
444443
Rvalue::Repeat(..) |
445444
Rvalue::Aggregate(..) |
445+
Rvalue::Discriminant(..) |
446446
Rvalue::Cast(..) |
447447
Rvalue::NullaryOp(..) |
448448
Rvalue::CheckedBinaryOp(..) |
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// compile-flags: -O
2+
3+
fn main() {
4+
let x = (if let Some(true) = Some(true) { 42 } else { 10 }) + 0;
5+
}
6+
7+
// END RUST SOURCE
8+
// START rustc.main.ConstProp.before.mir
9+
// bb0: {
10+
// ...
11+
// _3 = std::option::Option::<bool>::Some(const true,);
12+
// _4 = discriminant(_3);
13+
// switchInt(move _4) -> [1isize: bb3, otherwise: bb2];
14+
// }
15+
// bb1: {
16+
// _2 = const 42i32;
17+
// goto -> bb4;
18+
// }
19+
// bb2: {
20+
// _2 = const 10i32;
21+
// goto -> bb4;
22+
// }
23+
// bb3: {
24+
// switchInt(((_3 as Some).0: bool)) -> [false: bb2, otherwise: bb1];
25+
// }
26+
// bb4: {
27+
// _1 = Add(move _2, const 0i32);
28+
// ...
29+
// }
30+
// END rustc.main.ConstProp.before.mir
31+
// START rustc.main.ConstProp.after.mir
32+
// bb0: {
33+
// ...
34+
// _3 = const Scalar(0x01) : std::option::Option<bool>;
35+
// _4 = const 1isize;
36+
// switchInt(const 1isize) -> [1isize: bb3, otherwise: bb2];
37+
// }
38+
// bb1: {
39+
// _2 = const 42i32;
40+
// goto -> bb4;
41+
// }
42+
// bb2: {
43+
// _2 = const 10i32;
44+
// goto -> bb4;
45+
// }
46+
// bb3: {
47+
// switchInt(const true) -> [false: bb2, otherwise: bb1];
48+
// }
49+
// bb4: {
50+
// _1 = Add(move _2, const 0i32);
51+
// ...
52+
// }
53+
// END rustc.main.ConstProp.after.mir

0 commit comments

Comments
 (0)