Skip to content

Commit 5ef9ad3

Browse files
committed
Add test
1 parent e67f529 commit 5ef9ad3

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// MIR for `constant_eq` after SimplifyCfg-initial
2+
3+
fn constant_eq(_1: &str, _2: bool) -> u32 {
4+
debug s => _1;
5+
debug b => _2;
6+
let mut _0: u32;
7+
let mut _3: (&str, bool);
8+
let mut _4: &str;
9+
let mut _5: bool;
10+
let mut _6: bool;
11+
let mut _7: bool;
12+
let mut _8: bool;
13+
let mut _9: &&str;
14+
let mut _10: &bool;
15+
let mut _11: bool;
16+
17+
bb0: {
18+
StorageLive(_3);
19+
StorageLive(_4);
20+
_4 = _1;
21+
StorageLive(_5);
22+
_5 = _2;
23+
_3 = (move _4, move _5);
24+
StorageDead(_5);
25+
StorageDead(_4);
26+
PlaceMention(_3);
27+
_8 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb13, unwind: bb21];
28+
}
29+
30+
bb1: {
31+
_7 = <str as PartialEq>::eq((_3.0: &str), const "b") -> [return: bb11, unwind: bb21];
32+
}
33+
34+
bb2: {
35+
_6 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb8, unwind: bb21];
36+
}
37+
38+
bb3: {
39+
switchInt((_3.1: bool)) -> [0: bb4, otherwise: bb5];
40+
}
41+
42+
bb4: {
43+
_0 = const 5_u32;
44+
goto -> bb20;
45+
}
46+
47+
bb5: {
48+
falseEdge -> [real: bb19, imaginary: bb4];
49+
}
50+
51+
bb6: {
52+
switchInt((_3.1: bool)) -> [0: bb3, otherwise: bb7];
53+
}
54+
55+
bb7: {
56+
falseEdge -> [real: bb18, imaginary: bb5];
57+
}
58+
59+
bb8: {
60+
switchInt(move _6) -> [0: bb3, otherwise: bb6];
61+
}
62+
63+
bb9: {
64+
switchInt((_3.1: bool)) -> [0: bb2, otherwise: bb10];
65+
}
66+
67+
bb10: {
68+
falseEdge -> [real: bb17, imaginary: bb7];
69+
}
70+
71+
bb11: {
72+
switchInt(move _7) -> [0: bb2, otherwise: bb9];
73+
}
74+
75+
bb12: {
76+
falseEdge -> [real: bb14, imaginary: bb10];
77+
}
78+
79+
bb13: {
80+
switchInt(move _8) -> [0: bb1, otherwise: bb12];
81+
}
82+
83+
bb14: {
84+
_9 = &fake (_3.0: &str);
85+
_10 = &fake (_3.1: bool);
86+
StorageLive(_11);
87+
_11 = const true;
88+
switchInt(move _11) -> [0: bb16, otherwise: bb15];
89+
}
90+
91+
bb15: {
92+
StorageDead(_11);
93+
FakeRead(ForMatchGuard, _9);
94+
FakeRead(ForMatchGuard, _10);
95+
_0 = const 1_u32;
96+
goto -> bb20;
97+
}
98+
99+
bb16: {
100+
StorageDead(_11);
101+
falseEdge -> [real: bb1, imaginary: bb10];
102+
}
103+
104+
bb17: {
105+
_0 = const 2_u32;
106+
goto -> bb20;
107+
}
108+
109+
bb18: {
110+
_0 = const 3_u32;
111+
goto -> bb20;
112+
}
113+
114+
bb19: {
115+
_0 = const 4_u32;
116+
goto -> bb20;
117+
}
118+
119+
bb20: {
120+
StorageDead(_3);
121+
return;
122+
}
123+
124+
bb21 (cleanup): {
125+
resume;
126+
}
127+
}

Diff for: tests/mir-opt/building/match/sort_candidates.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
// Check specific cases of sorting candidates in match lowering.
33
#![feature(exclusive_range_pattern)]
44

5+
// EMIT_MIR sort_candidates.constant_eq.SimplifyCfg-initial.after.mir
6+
fn constant_eq(s: &str, b: bool) -> u32 {
7+
// For now we test "a" twice.
8+
match (s, b) {
9+
("a", _) if true => 1,
10+
("b", true) => 2,
11+
("a", true) => 3,
12+
(_, true) => 4,
13+
_ => 5,
14+
}
15+
}
16+
517
// EMIT_MIR sort_candidates.disjoint_ranges.SimplifyCfg-initial.after.mir
618
fn disjoint_ranges() {
719
let x = 3;

0 commit comments

Comments
 (0)