From e50ce67631bc8f8e28042112a924b73c6081dc71 Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Thu, 6 May 2021 13:32:35 +0500 Subject: Do not do match check if lowering failed. --- crates/hir_ty/src/diagnostics/expr.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index 8f141a308..929c4a9cc 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs @@ -388,14 +388,26 @@ impl<'a, 'b> ExprValidator<'a, 'b> { let pattern_arena = RefCell::new(PatternArena::new()); + let mut have_errors = false; let m_arms: Vec<_> = arms .iter() .map(|arm| usefulness::MatchArm { - pat: self.lower_pattern(arm.pat, &mut pattern_arena.borrow_mut(), db, &body), + pat: self.lower_pattern( + arm.pat, + &mut pattern_arena.borrow_mut(), + db, + &body, + &mut have_errors, + ), has_guard: arm.guard.is_some(), }) .collect(); + // Bail out early if lowering failed. + if have_errors { + return; + } + let cx = usefulness::MatchCheckCtx { module: self.owner.module(db.upcast()), match_expr, @@ -442,10 +454,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> { pattern_arena: &mut PatternArena, db: &dyn HirDatabase, body: &Body, + have_errors: &mut bool, ) -> pattern::PatId { let mut patcx = pattern::PatCtxt::new(db, &self.infer, body); let pattern = patcx.lower_pattern(pat); - pattern_arena.alloc(expand_pattern(pattern)) + let pattern = pattern_arena.alloc(expand_pattern(pattern)); + if !patcx.errors.is_empty() { + *have_errors = true; + } + pattern } fn validate_results_in_tail_expr(&mut self, body_id: ExprId, id: ExprId, db: &dyn HirDatabase) { -- cgit v1.2.3