From da6752d5f9a18ba58adb6a2e72d30a83532ec8a6 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Mon, 6 Apr 2020 06:55:25 -0700 Subject: missing match arms diagnostic change source to match expression --- crates/ra_hir_ty/src/_match.rs | 2 +- crates/ra_hir_ty/src/diagnostics.rs | 3 ++- crates/ra_hir_ty/src/expr.rs | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs index f502a9208..02472e0c0 100644 --- a/crates/ra_hir_ty/src/_match.rs +++ b/crates/ra_hir_ty/src/_match.rs @@ -545,7 +545,7 @@ mod tests { assert_snapshot!( check_diagnostic_message(content), - @"\"{\\n }\": Missing match arm\n" + @"\"()\": Missing match arm\n" ); } diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 3457905e2..8cbce1168 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs @@ -65,6 +65,7 @@ impl AstDiagnostic for MissingFields { #[derive(Debug)] pub struct MissingMatchArms { pub file: HirFileId, + pub match_expr: AstPtr, pub arms: AstPtr, } @@ -73,7 +74,7 @@ impl Diagnostic for MissingMatchArms { String::from("Missing match arm") } fn source(&self) -> InFile { - InFile { file_id: self.file, value: self.arms.into() } + InFile { file_id: self.file, value: self.match_expr.into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { self diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index 6efed6f9e..19323fda1 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs @@ -125,9 +125,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> { if let Some(expr) = source_ptr.value.left() { let root = source_ptr.file_syntax(db.upcast()); if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) { - if let Some(arms) = match_expr.match_arm_list() { + if let (Some(match_expr), Some(arms)) = + (match_expr.expr(), match_expr.match_arm_list()) + { self.sink.push(MissingMatchArms { file: source_ptr.file_id, + match_expr: AstPtr::new(&match_expr), arms: AstPtr::new(&arms), }) } -- cgit v1.2.3