@@ -121,6 +121,24 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
121
121
check_for_bindings_named_same_as_variants ( self , pat) ;
122
122
}
123
123
124
+ fn lower_pattern < ' p > (
125
+ & self ,
126
+ cx : & mut MatchCheckCtxt < ' p , ' tcx > ,
127
+ pat : & ' tcx hir:: Pat < ' tcx > ,
128
+ have_errors : & mut bool ,
129
+ ) -> ( & ' p super :: Pat < ' tcx > , Ty < ' tcx > ) {
130
+ let mut patcx = PatCtxt :: new ( self . tcx , self . param_env , self . tables ) ;
131
+ patcx. include_lint_checks ( ) ;
132
+ let pattern = patcx. lower_pattern ( pat) ;
133
+ let pattern_ty = pattern. ty ;
134
+ let pattern: & _ = cx. pattern_arena . alloc ( expand_pattern ( cx, pattern) ) ;
135
+ if !patcx. errors . is_empty ( ) {
136
+ * have_errors = true ;
137
+ patcx. report_inlining_errors ( pat. span ) ;
138
+ }
139
+ ( pattern, pattern_ty)
140
+ }
141
+
124
142
fn check_match (
125
143
& mut self ,
126
144
scrut : & hir:: Expr < ' _ > ,
@@ -139,14 +157,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
139
157
let inlined_arms: Vec < _ > = arms
140
158
. iter ( )
141
159
. map ( |arm| {
142
- let mut patcx = PatCtxt :: new ( self . tcx , self . param_env , self . tables ) ;
143
- patcx. include_lint_checks ( ) ;
144
- let pattern = patcx. lower_pattern ( & arm. pat ) ;
145
- let pattern: & _ = cx. pattern_arena . alloc ( expand_pattern ( cx, pattern) ) ;
146
- if !patcx. errors . is_empty ( ) {
147
- patcx. report_inlining_errors ( arm. pat . span ) ;
148
- have_errors = true ;
149
- }
160
+ let ( pattern, _) = self . lower_pattern ( cx, & arm. pat , & mut have_errors) ;
150
161
( pattern, & * arm. pat , arm. guard . is_some ( ) )
151
162
} )
152
163
. collect ( ) ;
@@ -171,11 +182,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
171
182
fn check_irrefutable ( & self , pat : & ' tcx Pat < ' tcx > , origin : & str , sp : Option < Span > ) {
172
183
let module = self . tcx . hir ( ) . get_module_parent ( pat. hir_id ) ;
173
184
MatchCheckCtxt :: create_and_enter ( self . tcx , self . param_env , module, |ref mut cx| {
174
- let mut patcx = PatCtxt :: new ( self . tcx , self . param_env , self . tables ) ;
175
- patcx. include_lint_checks ( ) ;
176
- let pattern = patcx. lower_pattern ( pat) ;
177
- let pattern_ty = pattern. ty ;
178
- let pattern = cx. pattern_arena . alloc ( expand_pattern ( cx, pattern) ) ;
185
+ let ( pattern, pattern_ty) = self . lower_pattern ( cx, pat, & mut false ) ;
179
186
let pats: Matrix < ' _ , ' _ > = vec ! [ PatStack :: from_pattern( pattern) ] . into_iter ( ) . collect ( ) ;
180
187
181
188
let witnesses = match check_not_useful ( cx, pattern_ty, & pats, pat. hir_id ) {
0 commit comments