Skip to content

Commit 5ed10b4

Browse files
committed
Move FlatPat::new into match_pair.rs
This makes it easier to perform coordinated modifications to `FlatPat::new` and `MatchPairTree::from_pattern`, because the two functions are heavily coupled.
1 parent 4a5c24f commit 5ed10b4

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,32 @@ fn prefix_slice_suffix<'a, 'tcx>(
6666
output_pairs
6767
}
6868

69+
impl<'tcx> FlatPat<'tcx> {
70+
/// Creates a `FlatPat` containing a simplified [`MatchPairTree`] list/forest
71+
/// for the given pattern.
72+
pub(crate) fn new(
73+
place: PlaceBuilder<'tcx>,
74+
pattern: &Pat<'tcx>,
75+
cx: &mut Builder<'_, 'tcx>,
76+
) -> Self {
77+
// Recursively build a tree of match pairs for the given pattern.
78+
let mut match_pairs = vec![];
79+
let mut extra_data = PatternExtraData {
80+
span: pattern.span,
81+
bindings: vec![],
82+
ascriptions: vec![],
83+
is_never: pattern.is_never_pattern(),
84+
};
85+
MatchPairTree::for_pattern(place, pattern, cx, &mut match_pairs, &mut extra_data);
86+
87+
FlatPat { match_pairs, extra_data }
88+
}
89+
}
90+
6991
impl<'tcx> MatchPairTree<'tcx> {
7092
/// Recursively builds a match pair tree for the given pattern and its
7193
/// subpatterns.
72-
pub(super) fn for_pattern(
94+
fn for_pattern(
7395
mut place_builder: PlaceBuilder<'tcx>,
7496
pattern: &Pat<'tcx>,
7597
cx: &mut Builder<'_, 'tcx>,

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -999,24 +999,6 @@ struct FlatPat<'tcx> {
999999
extra_data: PatternExtraData<'tcx>,
10001000
}
10011001

1002-
impl<'tcx> FlatPat<'tcx> {
1003-
/// Creates a `FlatPat` containing a simplified [`MatchPairTree`] list/forest
1004-
/// for the given pattern.
1005-
fn new(place: PlaceBuilder<'tcx>, pattern: &Pat<'tcx>, cx: &mut Builder<'_, 'tcx>) -> Self {
1006-
// Recursively build a tree of match pairs for the given pattern.
1007-
let mut match_pairs = vec![];
1008-
let mut extra_data = PatternExtraData {
1009-
span: pattern.span,
1010-
bindings: Vec::new(),
1011-
ascriptions: Vec::new(),
1012-
is_never: pattern.is_never_pattern(),
1013-
};
1014-
MatchPairTree::for_pattern(place, pattern, cx, &mut match_pairs, &mut extra_data);
1015-
1016-
Self { match_pairs, extra_data }
1017-
}
1018-
}
1019-
10201002
/// Candidates are a generalization of (a) top-level match arms, and
10211003
/// (b) sub-branches of or-patterns, allowing the match-lowering process to handle
10221004
/// them both in a mostly-uniform way. For example, the list of candidates passed

0 commit comments

Comments
 (0)