aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/diagnostics.rs
diff options
context:
space:
mode:
authorPaul Daniel Faria <[email protected]>2020-05-27 13:51:08 +0100
committerPaul Daniel Faria <[email protected]>2020-06-27 15:10:26 +0100
commit9ce44be2ab7e9a99eece1c2e254f15ad1c6d73c5 (patch)
tree904c2c860ff62242bb01af23ea662c70cbe1152f /crates/ra_hir_ty/src/diagnostics.rs
parentb9569886a915f2411adaecbcad28eda8b163c3e3 (diff)
Address review comments, have MissingUnsafe diagnostic point to each unsafe use, update tests
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs15
1 files changed, 6 insertions, 9 deletions
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 @@
3use std::any::Any; 3use std::any::Any;
4 4
5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; 5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
6use ra_syntax::{ 6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
7 ast::{self, NameOwner},
8 AstNode, AstPtr, SyntaxNodePtr,
9};
10use stdx::format_to; 7use stdx::format_to;
11 8
12pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; 9pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path};
@@ -176,15 +173,15 @@ impl AstDiagnostic for BreakOutsideOfLoop {
176#[derive(Debug)] 173#[derive(Debug)]
177pub struct MissingUnsafe { 174pub struct MissingUnsafe {
178 pub file: HirFileId, 175 pub file: HirFileId,
179 pub fn_def: AstPtr<ast::FnDef>, 176 pub expr: AstPtr<ast::Expr>,
180} 177}
181 178
182impl Diagnostic for MissingUnsafe { 179impl Diagnostic for MissingUnsafe {
183 fn message(&self) -> String { 180 fn message(&self) -> String {
184 format!("Missing unsafe keyword on fn") 181 format!("This operation is unsafe and requires an unsafe function or block")
185 } 182 }
186 fn source(&self) -> InFile<SyntaxNodePtr> { 183 fn source(&self) -> InFile<SyntaxNodePtr> {
187 InFile { file_id: self.file, value: self.fn_def.clone().into() } 184 InFile { file_id: self.file, value: self.expr.clone().into() }
188 } 185 }
189 fn as_any(&self) -> &(dyn Any + Send + 'static) { 186 fn as_any(&self) -> &(dyn Any + Send + 'static) {
190 self 187 self
@@ -192,11 +189,11 @@ impl Diagnostic for MissingUnsafe {
192} 189}
193 190
194impl AstDiagnostic for MissingUnsafe { 191impl AstDiagnostic for MissingUnsafe {
195 type AST = ast::Name; 192 type AST = ast::Expr;
196 193
197 fn ast(&self, db: &impl AstDatabase) -> Self::AST { 194 fn ast(&self, db: &impl AstDatabase) -> Self::AST {
198 let root = db.parse_or_expand(self.source().file_id).unwrap(); 195 let root = db.parse_or_expand(self.source().file_id).unwrap();
199 let node = self.source().value.to_node(&root); 196 let node = self.source().value.to_node(&root);
200 ast::FnDef::cast(node).unwrap().name().unwrap() 197 ast::Expr::cast(node).unwrap()
201 } 198 }
202} 199}