@@ -140,6 +140,11 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
140
140
( pattern, pattern_ty)
141
141
}
142
142
143
+ fn check_in_cx ( & self , hir_id : HirId , f : impl FnOnce ( MatchCheckCtxt < ' _ , ' tcx > ) ) {
144
+ let module = self . tcx . hir ( ) . get_module_parent ( hir_id) ;
145
+ MatchCheckCtxt :: create_and_enter ( self . tcx , self . param_env , module, |cx| f ( cx) ) ;
146
+ }
147
+
143
148
fn check_match (
144
149
& mut self ,
145
150
scrut : & hir:: Expr < ' _ > ,
@@ -151,8 +156,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
151
156
self . check_patterns ( arm. guard . is_some ( ) , & arm. pat ) ;
152
157
}
153
158
154
- let module = self . tcx . hir ( ) . get_module_parent ( scrut. hir_id ) ;
155
- MatchCheckCtxt :: create_and_enter ( self . tcx , self . param_env , module, |ref mut cx| {
159
+ self . check_in_cx ( scrut. hir_id , |ref mut cx| {
156
160
let mut have_errors = false ;
157
161
158
162
let inlined_arms: Vec < _ > = arms
@@ -180,8 +184,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
180
184
}
181
185
182
186
fn check_irrefutable ( & self , pat : & ' tcx Pat < ' tcx > , origin : & str , sp : Option < Span > ) {
183
- let module = self . tcx . hir ( ) . get_module_parent ( pat. hir_id ) ;
184
- MatchCheckCtxt :: create_and_enter ( self . tcx , self . param_env , module, |ref mut cx| {
187
+ self . check_in_cx ( pat. hir_id , |ref mut cx| {
185
188
let ( pattern, pattern_ty) = self . lower_pattern ( cx, pat, & mut false ) ;
186
189
let pats: Matrix < ' _ , ' _ > = vec ! [ PatStack :: from_pattern( pattern) ] . into_iter ( ) . collect ( ) ;
187
190
0 commit comments