Skip to content

Commit 0610f59

Browse files
committed
Inline simplify_match_pair
1 parent b1a0607 commit 0610f59

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

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

+18-34
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6060
let mut simplified_match_pairs = Vec::new();
6161
// Repeatedly simplify match pairs until we're left with only unsimplifiable ones.
6262
loop {
63-
for match_pair in mem::take(match_pairs) {
64-
if let Err(match_pair) = self.simplify_match_pair(
65-
match_pair,
66-
candidate_bindings,
67-
candidate_ascriptions,
68-
match_pairs,
69-
) {
63+
for mut match_pair in mem::take(match_pairs) {
64+
if let TestCase::Irrefutable { binding, ascription } = match_pair.test_case {
65+
if let Some(binding) = binding {
66+
candidate_bindings.push(binding);
67+
}
68+
if let Some(ascription) = ascription {
69+
candidate_ascriptions.push(ascription);
70+
}
71+
// Simplifiable pattern; we replace it with its subpairs and simplify further.
72+
match_pairs.append(&mut match_pair.subpairs);
73+
} else {
74+
// Unsimplifiable pattern; we recursively simplify its subpairs and don't
75+
// process it further.
76+
self.simplify_match_pairs(
77+
&mut match_pair.subpairs,
78+
candidate_bindings,
79+
candidate_ascriptions,
80+
);
7081
simplified_match_pairs.push(match_pair);
7182
}
7283
}
@@ -115,31 +126,4 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
115126
})
116127
.collect()
117128
}
118-
119-
/// Tries to simplify `match_pair`, returning `Ok(())` if successful. If successful, new match
120-
/// pairs and bindings will have been pushed into the respective `Vec`s. If no simplification is
121-
/// possible, `Err` is returned.
122-
fn simplify_match_pair<'pat>(
123-
&mut self,
124-
mut match_pair: MatchPair<'pat, 'tcx>,
125-
bindings: &mut Vec<Binding<'tcx>>,
126-
ascriptions: &mut Vec<Ascription<'tcx>>,
127-
match_pairs: &mut Vec<MatchPair<'pat, 'tcx>>,
128-
) -> Result<(), MatchPair<'pat, 'tcx>> {
129-
if let TestCase::Irrefutable { binding, ascription } = match_pair.test_case {
130-
if let Some(binding) = binding {
131-
bindings.push(binding);
132-
}
133-
if let Some(ascription) = ascription {
134-
ascriptions.push(ascription);
135-
}
136-
// Simplifiable pattern; we replace it with its subpairs.
137-
match_pairs.append(&mut match_pair.subpairs);
138-
Ok(())
139-
} else {
140-
// Unsimplifiable pattern; we recursively simplify its subpairs.
141-
self.simplify_match_pairs(&mut match_pair.subpairs, bindings, ascriptions);
142-
Err(match_pair)
143-
}
144-
}
145129
}

0 commit comments

Comments
 (0)