@@ -26,7 +26,6 @@ use crate::builder::{
2626
2727// helper functions, broken out by category:
2828mod match_pair;
29- mod simplify;
3029mod test;
3130mod util;
3231
@@ -987,18 +986,16 @@ impl<'tcx> PatternExtraData<'tcx> {
987986}
988987
989988/// 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.
991990///
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.
995994///
996995/// Will typically be incorporated into a [`Candidate`].
997996#[ derive( Debug , Clone ) ]
998997struct FlatPat < ' tcx > {
999998 /// 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.
1002999 match_pairs : Vec < MatchPairTree < ' tcx > > ,
10031000
10041001 extra_data : PatternExtraData < ' tcx > ,
@@ -1017,7 +1014,6 @@ impl<'tcx> FlatPat<'tcx> {
10171014 is_never : pattern. is_never_pattern ( ) ,
10181015 } ;
10191016 MatchPairTree :: for_pattern ( place, pattern, cx, & mut match_pairs, & mut extra_data) ;
1020- cx. simplify_match_pairs ( & mut match_pairs, & mut extra_data) ;
10211017
10221018 Self { match_pairs, extra_data }
10231019 }
@@ -1124,7 +1120,7 @@ impl<'tcx> Candidate<'tcx> {
11241120
11251121 /// Incorporates an already-simplified [`FlatPat`] into a new candidate.
11261122 fn from_flat_pat ( flat_pat : FlatPat < ' tcx > , has_guard : bool ) -> Self {
1127- Candidate {
1123+ let mut this = Candidate {
11281124 match_pairs : flat_pat. match_pairs ,
11291125 extra_data : flat_pat. extra_data ,
11301126 has_guard,
@@ -1133,7 +1129,14 @@ impl<'tcx> Candidate<'tcx> {
11331129 otherwise_block : None ,
11341130 pre_binding_block : None ,
11351131 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 { .. } ) ) ;
11371140 }
11381141
11391142 /// Returns whether the first match pair of this candidate is an or-pattern.
0 commit comments