diff options
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 15 |
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 @@ | |||
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::{ | 6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; |
7 | ast::{self, NameOwner}, | ||
8 | AstNode, AstPtr, SyntaxNodePtr, | ||
9 | }; | ||
10 | use stdx::format_to; | 7 | use stdx::format_to; |
11 | 8 | ||
12 | pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; | 9 | pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; |
@@ -176,15 +173,15 @@ impl AstDiagnostic for BreakOutsideOfLoop { | |||
176 | #[derive(Debug)] | 173 | #[derive(Debug)] |
177 | pub struct MissingUnsafe { | 174 | pub 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 | ||
182 | impl Diagnostic for MissingUnsafe { | 179 | impl 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 | ||
194 | impl AstDiagnostic for MissingUnsafe { | 191 | impl 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 | } |