Skip to content

Commit de7f16d

Browse files
committed
check_match: extract common logic
1 parent 8a79d08 commit de7f16d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/librustc_mir_build/hair/pattern/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
586586
tcx: TyCtxt<'tcx>,
587587
param_env: ty::ParamEnv<'tcx>,
588588
module: DefId,
589-
f: impl for<'b> FnOnce(MatchCheckCtxt<'b, 'tcx>) -> R,
589+
f: impl FnOnce(MatchCheckCtxt<'_, 'tcx>) -> R,
590590
) -> R {
591591
let pattern_arena = TypedArena::default();
592592

src/librustc_mir_build/hair/pattern/check_match.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)