Skip to content

Commit 753680a

Browse files
committed
Consistently set MatchVisitor.error on error
1 parent 12ebc3d commit 753680a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use rustc_pattern_analysis::errors::Uncovered;
22
use rustc_pattern_analysis::rustc::{
3-
Constructor, DeconstructedPat, RustcMatchCheckCtxt as MatchCheckCtxt, Usefulness,
3+
Constructor, DeconstructedPat, MatchArm, RustcMatchCheckCtxt as MatchCheckCtxt, Usefulness,
44
UsefulnessReport, WitnessPat,
55
};
6-
use rustc_pattern_analysis::{analyze_match, MatchArm};
76

87
use crate::errors::*;
98

@@ -386,6 +385,18 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
386385
}
387386
}
388387

388+
fn analyze_patterns(
389+
&mut self,
390+
cx: &MatchCheckCtxt<'p, 'tcx>,
391+
arms: &[MatchArm<'p, 'tcx>],
392+
scrut_ty: Ty<'tcx>,
393+
) -> Result<UsefulnessReport<'p, 'tcx>, ErrorGuaranteed> {
394+
rustc_pattern_analysis::analyze_match(&cx, &arms, scrut_ty).map_err(|err| {
395+
self.error = Err(err);
396+
err
397+
})
398+
}
399+
389400
#[instrument(level = "trace", skip(self))]
390401
fn check_let(&mut self, pat: &'p Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
391402
assert!(self.let_source != LetSource::None);
@@ -431,14 +442,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
431442
}
432443
}
433444

434-
let scrut_ty = scrut.ty;
435-
let report = match analyze_match(&cx, &tarms, scrut_ty) {
436-
Ok(report) => report,
437-
Err(err) => {
438-
self.error = Err(err);
439-
return;
440-
}
441-
};
445+
let Ok(report) = self.analyze_patterns(&cx, &tarms, scrut.ty) else { return };
442446

443447
match source {
444448
// Don't report arm reachability of desugared `match $iter.into_iter() { iter => .. }`
@@ -470,7 +474,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
470474
);
471475
} else {
472476
self.error = Err(report_non_exhaustive_match(
473-
&cx, self.thir, scrut_ty, scrut.span, witnesses, arms, expr_span,
477+
&cx, self.thir, scrut.ty, scrut.span, witnesses, arms, expr_span,
474478
));
475479
}
476480
}
@@ -552,7 +556,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
552556
let cx = self.new_cx(refutability, None, scrut, pat.span);
553557
let pat = self.lower_pattern(&cx, pat)?;
554558
let arms = [MatchArm { pat, arm_data: self.lint_level, has_guard: false }];
555-
let report = analyze_match(&cx, &arms, pat.ty().inner())?;
559+
let report = self.analyze_patterns(&cx, &arms, pat.ty().inner())?;
556560
Ok((cx, report))
557561
}
558562

0 commit comments

Comments
 (0)