Skip to content

Commit cef0cf1

Browse files
committed
Update arm + guard pat combination and guard pat handling overall
1 parent 4188f21 commit cef0cf1

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

  • compiler/rustc_mir_build/src/builder/matches

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ struct PatternExtraData<'tcx> {
999999

10001000
impl<'tcx> PatternExtraData<'tcx> {
10011001
fn is_empty(&self) -> bool {
1002-
self.bindings.is_empty() && self.ascriptions.is_empty()
1002+
self.bindings.is_empty() && self.ascriptions.is_empty() && self.guard_patterns.is_empty()
10031003
}
10041004
}
10051005

@@ -1102,11 +1102,12 @@ struct Candidate<'tcx> {
11021102
/// - See [`Builder::remove_never_subcandidates`].
11031103
subcandidates: Vec<Candidate<'tcx>>,
11041104

1105-
/// ...and if there are guards they must be evaluated; if they're `false` then branch to `otherwise_block`.
1105+
/// ...and if there are arm guards they must be evaluated; if they're `false` then branch to
1106+
/// `otherwise_block`.
11061107
///
11071108
/// ---
11081109
/// For subcandidates, this is copied from the parent candidate
1109-
guards: Vec<OrderedPatternData<ExprId>>,
1110+
guards: Vec<ExprId>,
11101111

11111112
/// Holds extra pattern data that was prepared by [`FlatPat`], including bindings and
11121113
/// ascriptions that must be established if this candidate succeeds.
@@ -1144,15 +1145,15 @@ impl<'tcx> Candidate<'tcx> {
11441145
// Use `FlatPat` to build simplified match pairs, then immediately
11451146
// incorporate them into a new candidate.
11461147
let flat_pat = FlatPat::new(place, pattern, cx);
1147-
let mut guards = flat_pat.extra_data.guard_patterns.clone();
1148+
let mut guards = Vec::new();
11481149
if let HasMatchGuard::Yes(g) = guard {
1149-
guards.push(OrderedPatternData::One(g));
1150-
};
1150+
guards.push(g);
1151+
}
11511152
Self::from_flat_pat(flat_pat, guards)
11521153
}
11531154

11541155
/// Incorporates an already-simplified [`FlatPat`] into a new candidate.
1155-
fn from_flat_pat(flat_pat: FlatPat<'tcx>, guards: Vec<OrderedPatternData<ExprId>>) -> Self {
1156+
fn from_flat_pat(flat_pat: FlatPat<'tcx>, guards: Vec<ExprId>) -> Self {
11561157
let mut this = Candidate {
11571158
match_pairs: flat_pat.match_pairs,
11581159
extra_data: flat_pat.extra_data,
@@ -1513,8 +1514,11 @@ impl<'tcx> MatchTreeSubBranch<'tcx> {
15131514
.collect(),
15141515
guards: sub_branch_ordered_pat_data(
15151516
parent_data.iter().map(|parent| parent.guard_patterns.as_slice()),
1516-
&candidate.guards,
1517-
),
1517+
&candidate.extra_data.guard_patterns,
1518+
)
1519+
.into_iter()
1520+
.chain(candidate.guards)
1521+
.collect(),
15181522
is_never: candidate.extra_data.is_never,
15191523
}
15201524
}
@@ -2074,7 +2078,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20742078
/// in match tree lowering.
20752079
fn merge_trivial_subcandidates(&mut self, candidate: &mut Candidate<'tcx>) {
20762080
assert!(!candidate.subcandidates.is_empty());
2077-
if !candidate.guards.is_empty() {
2081+
if !candidate.guards.is_empty() || !candidate.extra_data.guard_patterns.is_empty() {
20782082
// FIXME(or_patterns; matthewjasper) Don't give up if we have a guard.
20792083
return;
20802084
}

0 commit comments

Comments
 (0)