@@ -140,6 +140,11 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
140140 ( pattern, pattern_ty)
141141 }
142142
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+
143148 fn check_match (
144149 & mut self ,
145150 scrut : & hir:: Expr < ' _ > ,
@@ -151,8 +156,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
151156 self . check_patterns ( arm. guard . is_some ( ) , & arm. pat ) ;
152157 }
153158
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| {
156160 let mut have_errors = false ;
157161
158162 let inlined_arms: Vec < _ > = arms
@@ -180,8 +184,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
180184 }
181185
182186 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| {
185188 let ( pattern, pattern_ty) = self . lower_pattern ( cx, pat, & mut false ) ;
186189 let pats: Matrix < ' _ , ' _ > = vec ! [ PatStack :: from_pattern( pattern) ] . into_iter ( ) . collect ( ) ;
187190
0 commit comments