Skip to content

Commit 7a31456

Browse files
committed
Make field_match_pairs push its output nodes to a vector
1 parent 4559163 commit 7a31456

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ use crate::builder::expr::as_place::{PlaceBase, PlaceBuilder};
99
use crate::builder::matches::{FlatPat, MatchPairTree, TestCase};
1010

1111
impl<'a, 'tcx> Builder<'a, 'tcx> {
12-
/// Builds and returns [`MatchPairTree`] subtrees, one for each pattern in
12+
/// Builds and pushes [`MatchPairTree`] subtrees, one for each pattern in
1313
/// `subpatterns`, representing the fields of a [`PatKind::Variant`] or
1414
/// [`PatKind::Leaf`].
1515
///
1616
/// Used internally by [`MatchPairTree::for_pattern`].
1717
fn field_match_pairs(
1818
&mut self,
19+
match_pairs: &mut Vec<MatchPairTree<'tcx>>,
1920
place: PlaceBuilder<'tcx>,
2021
subpatterns: &[FieldPat<'tcx>],
21-
) -> Vec<MatchPairTree<'tcx>> {
22-
subpatterns
23-
.iter()
24-
.map(|fieldpat| {
25-
let place =
26-
place.clone_project(PlaceElem::Field(fieldpat.field, fieldpat.pattern.ty));
27-
MatchPairTree::for_pattern(place, &fieldpat.pattern, self)
28-
})
29-
.collect()
22+
) {
23+
for fieldpat in subpatterns {
24+
let place = place.clone_project(PlaceElem::Field(fieldpat.field, fieldpat.pattern.ty));
25+
match_pairs.push(MatchPairTree::for_pattern(place, &fieldpat.pattern, self));
26+
}
3027
}
3128

3229
/// Builds [`MatchPairTree`] subtrees for the prefix/middle/suffix parts of an
@@ -215,7 +212,7 @@ impl<'tcx> MatchPairTree<'tcx> {
215212

216213
PatKind::Variant { adt_def, variant_index, args, ref subpatterns } => {
217214
let downcast_place = place_builder.downcast(adt_def, variant_index); // `(x as Variant)`
218-
subpairs = cx.field_match_pairs(downcast_place, subpatterns);
215+
cx.field_match_pairs(&mut subpairs, downcast_place, subpatterns);
219216

220217
let irrefutable = adt_def.variants().iter_enumerated().all(|(i, v)| {
221218
i == variant_index
@@ -233,7 +230,7 @@ impl<'tcx> MatchPairTree<'tcx> {
233230
}
234231

235232
PatKind::Leaf { ref subpatterns } => {
236-
subpairs = cx.field_match_pairs(place_builder, subpatterns);
233+
cx.field_match_pairs(&mut subpairs, place_builder, subpatterns);
237234
default_irrefutable()
238235
}
239236

0 commit comments

Comments
 (0)