|
1 | 1 | use rustc_pattern_analysis::errors::Uncovered;
|
2 | 2 | use rustc_pattern_analysis::rustc::{
|
3 |
| - Constructor, DeconstructedPat, RustcMatchCheckCtxt as MatchCheckCtxt, Usefulness, |
| 3 | + Constructor, DeconstructedPat, MatchArm, RustcMatchCheckCtxt as MatchCheckCtxt, Usefulness, |
4 | 4 | UsefulnessReport, WitnessPat,
|
5 | 5 | };
|
6 |
| -use rustc_pattern_analysis::{analyze_match, MatchArm}; |
7 | 6 |
|
8 | 7 | use crate::errors::*;
|
9 | 8 |
|
@@ -386,6 +385,18 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
|
386 | 385 | }
|
387 | 386 | }
|
388 | 387 |
|
| 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 | + |
389 | 400 | #[instrument(level = "trace", skip(self))]
|
390 | 401 | fn check_let(&mut self, pat: &'p Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
|
391 | 402 | assert!(self.let_source != LetSource::None);
|
@@ -431,14 +442,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
|
431 | 442 | }
|
432 | 443 | }
|
433 | 444 |
|
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 }; |
442 | 446 |
|
443 | 447 | match source {
|
444 | 448 | // Don't report arm reachability of desugared `match $iter.into_iter() { iter => .. }`
|
@@ -470,7 +474,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
|
470 | 474 | );
|
471 | 475 | } else {
|
472 | 476 | 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, |
474 | 478 | ));
|
475 | 479 | }
|
476 | 480 | }
|
@@ -552,7 +556,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
|
552 | 556 | let cx = self.new_cx(refutability, None, scrut, pat.span);
|
553 | 557 | let pat = self.lower_pattern(&cx, pat)?;
|
554 | 558 | 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())?; |
556 | 560 | Ok((cx, report))
|
557 | 561 | }
|
558 | 562 |
|
|
0 commit comments