From 9ce44be2ab7e9a99eece1c2e254f15ad1c6d73c5 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Wed, 27 May 2020 08:51:08 -0400 Subject: Address review comments, have MissingUnsafe diagnostic point to each unsafe use, update tests --- crates/ra_hir_ty/src/diagnostics.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir_ty/src/diagnostics.rs') diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 0b7bcdc9d..a59efb347 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs @@ -3,10 +3,7 @@ use std::any::Any; use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; -use ra_syntax::{ - ast::{self, NameOwner}, - AstNode, AstPtr, SyntaxNodePtr, -}; +use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; use stdx::format_to; pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; @@ -176,15 +173,15 @@ impl AstDiagnostic for BreakOutsideOfLoop { #[derive(Debug)] pub struct MissingUnsafe { pub file: HirFileId, - pub fn_def: AstPtr, + pub expr: AstPtr, } impl Diagnostic for MissingUnsafe { fn message(&self) -> String { - format!("Missing unsafe keyword on fn") + format!("This operation is unsafe and requires an unsafe function or block") } fn source(&self) -> InFile { - InFile { file_id: self.file, value: self.fn_def.clone().into() } + InFile { file_id: self.file, value: self.expr.clone().into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { self @@ -192,11 +189,11 @@ impl Diagnostic for MissingUnsafe { } impl AstDiagnostic for MissingUnsafe { - type AST = ast::Name; + type AST = ast::Expr; fn ast(&self, db: &impl AstDatabase) -> Self::AST { let root = db.parse_or_expand(self.source().file_id).unwrap(); let node = self.source().value.to_node(&root); - ast::FnDef::cast(node).unwrap().name().unwrap() + ast::Expr::cast(node).unwrap() } } -- cgit v1.2.3