diff options
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 33 |
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 @@ | |||
3 | use std::any::Any; | 3 | use std::any::Any; |
4 | 4 | ||
5 | use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; | 5 | use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; |
6 | use ra_syntax::{ast::{self, NameOwner}, AstNode, AstPtr, SyntaxNodePtr}; | 6 | use ra_syntax::{ |
7 | ast::{self, NameOwner}, | ||
8 | AstNode, AstPtr, SyntaxNodePtr, | ||
9 | }; | ||
7 | use stdx::format_to; | 10 | use stdx::format_to; |
8 | 11 | ||
9 | pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; | 12 | pub 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)] | ||
202 | pub struct UnnecessaryUnsafe { | ||
203 | pub file: HirFileId, | ||
204 | pub fn_def: AstPtr<ast::FnDef>, | ||
205 | } | ||
206 | |||
207 | impl 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 | |||
219 | impl 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 | } | ||