@@ -26,7 +26,6 @@ use crate::builder::{
26
26
27
27
// helper functions, broken out by category:
28
28
mod match_pair;
29
- mod simplify;
30
29
mod test;
31
30
mod util;
32
31
@@ -987,18 +986,16 @@ impl<'tcx> PatternExtraData<'tcx> {
987
986
}
988
987
989
988
/// A pattern in a form suitable for lowering the match tree, with all irrefutable
990
- /// patterns simplified away, and or-patterns sorted to the end .
989
+ /// patterns simplified away.
991
990
///
992
- /// Here, "flat" indicates that the pattern's match pairs have been recursively
993
- /// simplified by [`Builder::simplify_match_pairs`] . They are not necessarily
994
- /// flat in an absolute sense.
991
+ /// Here, "flat" indicates that irrefutable nodes in the pattern tree have been
992
+ /// recursively replaced with their refutable subpatterns . They are not
993
+ /// necessarily flat in an absolute sense.
995
994
///
996
995
/// Will typically be incorporated into a [`Candidate`].
997
996
#[ derive( Debug , Clone ) ]
998
997
struct FlatPat < ' tcx > {
999
998
/// To match the pattern, all of these must be satisfied...
1000
- // Invariant: all the match pairs are recursively simplified.
1001
- // Invariant: or-patterns must be sorted to the end.
1002
999
match_pairs : Vec < MatchPairTree < ' tcx > > ,
1003
1000
1004
1001
extra_data : PatternExtraData < ' tcx > ,
@@ -1017,7 +1014,6 @@ impl<'tcx> FlatPat<'tcx> {
1017
1014
is_never : pattern. is_never_pattern ( ) ,
1018
1015
} ;
1019
1016
MatchPairTree :: for_pattern ( place, pattern, cx, & mut match_pairs, & mut extra_data) ;
1020
- cx. simplify_match_pairs ( & mut match_pairs, & mut extra_data) ;
1021
1017
1022
1018
Self { match_pairs, extra_data }
1023
1019
}
@@ -1124,7 +1120,7 @@ impl<'tcx> Candidate<'tcx> {
1124
1120
1125
1121
/// Incorporates an already-simplified [`FlatPat`] into a new candidate.
1126
1122
fn from_flat_pat ( flat_pat : FlatPat < ' tcx > , has_guard : bool ) -> Self {
1127
- Candidate {
1123
+ let mut this = Candidate {
1128
1124
match_pairs : flat_pat. match_pairs ,
1129
1125
extra_data : flat_pat. extra_data ,
1130
1126
has_guard,
@@ -1133,7 +1129,14 @@ impl<'tcx> Candidate<'tcx> {
1133
1129
otherwise_block : None ,
1134
1130
pre_binding_block : None ,
1135
1131
false_edge_start_block : None ,
1136
- }
1132
+ } ;
1133
+ this. sort_match_pairs ( ) ;
1134
+ this
1135
+ }
1136
+
1137
+ /// Restores the invariant that or-patterns must be sorted to the end.
1138
+ fn sort_match_pairs ( & mut self ) {
1139
+ self . match_pairs . sort_by_key ( |pair| matches ! ( pair. test_case, TestCase :: Or { .. } ) ) ;
1137
1140
}
1138
1141
1139
1142
/// Returns whether the first match pair of this candidate is an or-pattern.
0 commit comments