Skip to content

Commit 75d2e67

Browse files
committed
Sort Eq candidates in the failure case too
1 parent 5ef9ad3 commit 75d2e67

File tree

3 files changed

+44
-51
lines changed

3 files changed

+44
-51
lines changed

Diff for: compiler/rustc_mir_build/src/build/matches/test.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
650650
}
651651
}
652652

653-
// FIXME(#29623): return `Some(1)` when the values are different.
654-
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
655-
if test_val == case_val =>
656-
{
657-
fully_matched = true;
658-
Some(TestBranch::Success)
653+
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val }) => {
654+
if test_val == case_val {
655+
fully_matched = true;
656+
Some(TestBranch::Success)
657+
} else {
658+
fully_matched = false;
659+
Some(TestBranch::Failure)
660+
}
659661
}
660662

661663
(

Diff for: tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir

+35-44
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ fn constant_eq(_1: &str, _2: bool) -> u32 {
99
let mut _5: bool;
1010
let mut _6: bool;
1111
let mut _7: bool;
12-
let mut _8: bool;
13-
let mut _9: &&str;
14-
let mut _10: &bool;
15-
let mut _11: bool;
12+
let mut _8: &&str;
13+
let mut _9: &bool;
14+
let mut _10: bool;
1615

1716
bb0: {
1817
StorageLive(_3);
@@ -24,104 +23,96 @@ fn constant_eq(_1: &str, _2: bool) -> u32 {
2423
StorageDead(_5);
2524
StorageDead(_4);
2625
PlaceMention(_3);
27-
_8 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb13, unwind: bb21];
26+
_7 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb11, unwind: bb19];
2827
}
2928

3029
bb1: {
31-
_7 = <str as PartialEq>::eq((_3.0: &str), const "b") -> [return: bb11, unwind: bb21];
30+
switchInt((_3.1: bool)) -> [0: bb2, otherwise: bb3];
3231
}
3332

3433
bb2: {
35-
_6 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb8, unwind: bb21];
34+
_0 = const 5_u32;
35+
goto -> bb18;
3636
}
3737

3838
bb3: {
39-
switchInt((_3.1: bool)) -> [0: bb4, otherwise: bb5];
39+
falseEdge -> [real: bb17, imaginary: bb2];
4040
}
4141

4242
bb4: {
43-
_0 = const 5_u32;
44-
goto -> bb20;
43+
falseEdge -> [real: bb12, imaginary: bb9];
4544
}
4645

4746
bb5: {
48-
falseEdge -> [real: bb19, imaginary: bb4];
47+
switchInt((_3.1: bool)) -> [0: bb1, otherwise: bb6];
4948
}
5049

5150
bb6: {
52-
switchInt((_3.1: bool)) -> [0: bb3, otherwise: bb7];
51+
falseEdge -> [real: bb16, imaginary: bb3];
5352
}
5453

5554
bb7: {
56-
falseEdge -> [real: bb18, imaginary: bb5];
55+
_6 = <str as PartialEq>::eq((_3.0: &str), const "b") -> [return: bb10, unwind: bb19];
5756
}
5857

5958
bb8: {
60-
switchInt(move _6) -> [0: bb3, otherwise: bb6];
59+
switchInt((_3.1: bool)) -> [0: bb1, otherwise: bb9];
6160
}
6261

6362
bb9: {
64-
switchInt((_3.1: bool)) -> [0: bb2, otherwise: bb10];
63+
falseEdge -> [real: bb15, imaginary: bb6];
6564
}
6665

6766
bb10: {
68-
falseEdge -> [real: bb17, imaginary: bb7];
67+
switchInt(move _6) -> [0: bb1, otherwise: bb8];
6968
}
7069

7170
bb11: {
72-
switchInt(move _7) -> [0: bb2, otherwise: bb9];
71+
switchInt(move _7) -> [0: bb7, otherwise: bb4];
7372
}
7473

7574
bb12: {
76-
falseEdge -> [real: bb14, imaginary: bb10];
75+
_8 = &fake (_3.0: &str);
76+
_9 = &fake (_3.1: bool);
77+
StorageLive(_10);
78+
_10 = const true;
79+
switchInt(move _10) -> [0: bb14, otherwise: bb13];
7780
}
7881

7982
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);
83+
StorageDead(_10);
84+
FakeRead(ForMatchGuard, _8);
9385
FakeRead(ForMatchGuard, _9);
94-
FakeRead(ForMatchGuard, _10);
9586
_0 = const 1_u32;
96-
goto -> bb20;
87+
goto -> bb18;
9788
}
9889

99-
bb16: {
100-
StorageDead(_11);
101-
falseEdge -> [real: bb1, imaginary: bb10];
90+
bb14: {
91+
StorageDead(_10);
92+
falseEdge -> [real: bb5, imaginary: bb9];
10293
}
10394

104-
bb17: {
95+
bb15: {
10596
_0 = const 2_u32;
106-
goto -> bb20;
97+
goto -> bb18;
10798
}
10899

109-
bb18: {
100+
bb16: {
110101
_0 = const 3_u32;
111-
goto -> bb20;
102+
goto -> bb18;
112103
}
113104

114-
bb19: {
105+
bb17: {
115106
_0 = const 4_u32;
116-
goto -> bb20;
107+
goto -> bb18;
117108
}
118109

119-
bb20: {
110+
bb18: {
120111
StorageDead(_3);
121112
return;
122113
}
123114

124-
bb21 (cleanup): {
115+
bb19 (cleanup): {
125116
resume;
126117
}
127118
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// EMIT_MIR sort_candidates.constant_eq.SimplifyCfg-initial.after.mir
66
fn constant_eq(s: &str, b: bool) -> u32 {
7-
// For now we test "a" twice.
7+
// Check that we only test "a" once
88
match (s, b) {
99
("a", _) if true => 1,
1010
("b", true) => 2,

0 commit comments

Comments
 (0)