Skip to content

Commit 8a222ff

Browse files
committed
Don't try to save an extra block
This is preparation for the next commit.
1 parent c5062f7 commit 8a222ff

15 files changed

+284
-268
lines changed

compiler/rustc_mir_build/src/build/matches/mod.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -2021,19 +2021,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20212021

20222022
// The block that we should branch to if none of the
20232023
// `target_candidates` match.
2024-
let remainder_start = if !remaining_candidates.is_empty() {
2025-
let remainder_start = self.cfg.start_new_block();
2026-
self.match_candidates(
2027-
span,
2028-
scrutinee_span,
2029-
remainder_start,
2030-
otherwise_block,
2031-
remaining_candidates,
2032-
);
2033-
remainder_start
2034-
} else {
2035-
otherwise_block
2036-
};
2024+
let remainder_start = self.cfg.start_new_block();
20372025

20382026
// For each outcome of test, process the candidates that still apply.
20392027
let target_blocks: FxIndexMap<_, _> = target_candidates
@@ -2061,6 +2049,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20612049
&test,
20622050
target_blocks,
20632051
);
2052+
2053+
self.match_candidates(
2054+
span,
2055+
scrutinee_span,
2056+
remainder_start,
2057+
otherwise_block,
2058+
remaining_candidates,
2059+
);
20642060
}
20652061
}
20662062

tests/mir-opt/building/issue_101867.main.built.after.mir

+11-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ fn main() -> () {
2727
StorageLive(_5);
2828
PlaceMention(_1);
2929
_6 = discriminant(_1);
30-
switchInt(move _6) -> [1: bb4, otherwise: bb3];
30+
switchInt(move _6) -> [1: bb5, otherwise: bb4];
3131
}
3232

3333
bb1: {
3434
StorageLive(_3);
3535
StorageLive(_4);
36-
_4 = begin_panic::<&str>(const "explicit panic") -> bb8;
36+
_4 = begin_panic::<&str>(const "explicit panic") -> bb9;
3737
}
3838

3939
bb2: {
@@ -43,31 +43,35 @@ fn main() -> () {
4343
}
4444

4545
bb3: {
46-
goto -> bb7;
46+
goto -> bb8;
4747
}
4848

4949
bb4: {
50-
falseEdge -> [real: bb6, imaginary: bb3];
50+
goto -> bb3;
5151
}
5252

5353
bb5: {
54-
goto -> bb3;
54+
falseEdge -> [real: bb7, imaginary: bb3];
5555
}
5656

5757
bb6: {
58+
goto -> bb4;
59+
}
60+
61+
bb7: {
5862
_5 = ((_1 as Some).0: u8);
5963
_0 = const ();
6064
StorageDead(_5);
6165
StorageDead(_1);
6266
return;
6367
}
6468

65-
bb7: {
69+
bb8: {
6670
StorageDead(_5);
6771
goto -> bb1;
6872
}
6973

70-
bb8 (cleanup): {
74+
bb9 (cleanup): {
7175
resume;
7276
}
7377
}

tests/mir-opt/building/issue_49232.main.built.after.mir

+19-15
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ fn main() -> () {
1717
}
1818

1919
bb1: {
20-
falseUnwind -> [real: bb2, unwind: bb14];
20+
falseUnwind -> [real: bb2, unwind: bb15];
2121
}
2222

2323
bb2: {
2424
StorageLive(_2);
2525
StorageLive(_3);
2626
_3 = const true;
2727
PlaceMention(_3);
28-
switchInt(_3) -> [0: bb4, otherwise: bb6];
28+
switchInt(_3) -> [0: bb5, otherwise: bb7];
2929
}
3030

3131
bb3: {
@@ -34,59 +34,63 @@ fn main() -> () {
3434
}
3535

3636
bb4: {
37-
falseEdge -> [real: bb8, imaginary: bb6];
37+
goto -> bb3;
3838
}
3939

4040
bb5: {
41-
goto -> bb3;
41+
falseEdge -> [real: bb9, imaginary: bb7];
4242
}
4343

4444
bb6: {
45-
_0 = const ();
46-
goto -> bb13;
45+
goto -> bb4;
4746
}
4847

4948
bb7: {
50-
goto -> bb3;
49+
_0 = const ();
50+
goto -> bb14;
5151
}
5252

5353
bb8: {
54-
_2 = const 4_i32;
55-
goto -> bb11;
54+
goto -> bb4;
5655
}
5756

5857
bb9: {
59-
unreachable;
58+
_2 = const 4_i32;
59+
goto -> bb12;
6060
}
6161

6262
bb10: {
63-
goto -> bb11;
63+
unreachable;
6464
}
6565

6666
bb11: {
67+
goto -> bb12;
68+
}
69+
70+
bb12: {
6771
FakeRead(ForLet(None), _2);
6872
StorageDead(_3);
6973
StorageLive(_5);
7074
StorageLive(_6);
7175
_6 = &_2;
72-
_5 = std::mem::drop::<&i32>(move _6) -> [return: bb12, unwind: bb14];
76+
_5 = std::mem::drop::<&i32>(move _6) -> [return: bb13, unwind: bb15];
7377
}
7478

75-
bb12: {
79+
bb13: {
7680
StorageDead(_6);
7781
StorageDead(_5);
7882
_1 = const ();
7983
StorageDead(_2);
8084
goto -> bb1;
8185
}
8286

83-
bb13: {
87+
bb14: {
8488
StorageDead(_3);
8589
StorageDead(_2);
8690
return;
8791
}
8892

89-
bb14 (cleanup): {
93+
bb15 (cleanup): {
9094
resume;
9195
}
9296
}

0 commit comments

Comments
 (0)