Skip to content

Commit e3e74bc

Browse files
committed
Make MatchPairTree::place non-optional
As the invariant indicated, this place could only be none for `TestCase::Irrefutable` nodes, which no longer exist.
1 parent e05df1c commit e3e74bc

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

Diff for: compiler/rustc_mir_build/src/builder/matches/match_pair.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl<'tcx> MatchPairTree<'tcx> {
115115
place_builder = place_builder.project(ProjectionElem::OpaqueCast(pattern.ty));
116116
}
117117

118+
// Place can be none if the pattern refers to a non-captured place in a closure.
118119
let place = place_builder.try_to_place(cx);
119120
let mut subpairs = Vec::new();
120121
let test_case = match pattern.kind {
@@ -320,7 +321,7 @@ impl<'tcx> MatchPairTree<'tcx> {
320321
if let Some(test_case) = test_case {
321322
// This pattern is refutable, so push a new match-pair node.
322323
match_pairs.push(MatchPairTree {
323-
place,
324+
place: place.expect("refutable patterns should always have a place to inspect"),
324325
test_case,
325326
subpairs,
326327
pattern_ty: pattern.ty,

Diff for: compiler/rustc_mir_build/src/builder/matches/mod.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1256,13 +1256,7 @@ impl<'tcx> TestCase<'tcx> {
12561256
#[derive(Debug, Clone)]
12571257
pub(crate) struct MatchPairTree<'tcx> {
12581258
/// This place...
1259-
///
1260-
/// ---
1261-
/// This can be `None` if it referred to a non-captured place in a closure.
1262-
///
1263-
/// Invariant: Can only be `None` when `test_case` is `Irrefutable`.
1264-
/// Therefore this must be `Some(_)` after simplification.
1265-
place: Option<Place<'tcx>>,
1259+
place: Place<'tcx>,
12661260

12671261
/// ... must pass this test...
12681262
test_case: TestCase<'tcx>,
@@ -2082,11 +2076,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20822076
// Extract the match-pair from the highest priority candidate
20832077
let match_pair = &candidates[0].match_pairs[0];
20842078
let test = self.pick_test_for_match_pair(match_pair);
2085-
// Unwrap is ok after simplification.
2086-
let match_place = match_pair.place.unwrap();
20872079
debug!(?test, ?match_pair);
20882080

2089-
(match_place, test)
2081+
(match_pair.place, test)
20902082
}
20912083

20922084
/// Given a test, we partition the input candidates into several buckets.

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
540540
// than one, but it'd be very unusual to have two sides that
541541
// both require tests; you'd expect one side to be simplified
542542
// away.)
543-
let (match_pair_index, match_pair) = candidate
544-
.match_pairs
545-
.iter()
546-
.enumerate()
547-
.find(|&(_, mp)| mp.place == Some(test_place))?;
543+
let (match_pair_index, match_pair) =
544+
candidate.match_pairs.iter().enumerate().find(|&(_, mp)| mp.place == test_place)?;
548545

549546
// If true, the match pair is completely entailed by its corresponding test
550547
// branch, so it can be removed. If false, the match pair is _compatible_
@@ -587,7 +584,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
587584
candidate
588585
.match_pairs
589586
.iter()
590-
.any(|mp| mp.place == Some(test_place) && is_covering_range(&mp.test_case))
587+
.any(|mp| mp.place == test_place && is_covering_range(&mp.test_case))
591588
};
592589
if sorted_candidates
593590
.get(&TestBranch::Failure)

Diff for: compiler/rustc_mir_build/src/builder/matches/util.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,10 @@ impl<'a, 'b, 'tcx> FakeBorrowCollector<'a, 'b, 'tcx> {
173173
// }
174174
// ```
175175
// Hence we fake borrow using a deep borrow.
176-
if let Some(place) = match_pair.place {
177-
self.fake_borrow(place, FakeBorrowKind::Deep);
178-
}
176+
self.fake_borrow(match_pair.place, FakeBorrowKind::Deep);
179177
} else {
180178
// Insert a Shallow borrow of any place that is switched on.
181-
if let Some(place) = match_pair.place {
182-
self.fake_borrow(place, FakeBorrowKind::Shallow);
183-
}
179+
self.fake_borrow(match_pair.place, FakeBorrowKind::Shallow);
184180

185181
for subpair in &match_pair.subpairs {
186182
self.visit_match_pair(subpair);

0 commit comments

Comments
 (0)