aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs33
1 files changed, 4 insertions, 29 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index c6ca322fa..0b7bcdc9d 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -3,7 +3,10 @@
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::{ast::{self, NameOwner}, AstNode, AstPtr, SyntaxNodePtr}; 6use ra_syntax::{
7 ast::{self, NameOwner},
8 AstNode, AstPtr, SyntaxNodePtr,
9};
7use stdx::format_to; 10use stdx::format_to;
8 11
9pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; 12pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path};
@@ -197,31 +200,3 @@ impl AstDiagnostic for MissingUnsafe {
197 ast::FnDef::cast(node).unwrap().name().unwrap() 200 ast::FnDef::cast(node).unwrap().name().unwrap()
198 } 201 }
199} 202}
200
201#[derive(Debug)]
202pub struct UnnecessaryUnsafe {
203 pub file: HirFileId,
204 pub fn_def: AstPtr<ast::FnDef>,
205}
206
207impl Diagnostic for UnnecessaryUnsafe {
208 fn message(&self) -> String {
209 format!("Unnecessary unsafe keyword on fn")
210 }
211 fn source(&self) -> InFile<SyntaxNodePtr> {
212 InFile { file_id: self.file, value: self.fn_def.clone().into() }
213 }
214 fn as_any(&self) -> &(dyn Any + Send + 'static) {
215 self
216 }
217}
218
219impl AstDiagnostic for UnnecessaryUnsafe {
220 type AST = ast::Name;
221
222 fn ast(&self, db: &impl AstDatabase) -> Self::AST {
223 let root = db.parse_or_expand(self.source().file_id).unwrap();
224 let node = self.source().value.to_node(&root);
225 ast::FnDef::cast(node).unwrap().name().unwrap()
226 }
227}