diff options
author | Paul Daniel Faria <[email protected]> | 2020-05-24 06:33:22 +0100 |
---|---|---|
committer | Paul Daniel Faria <[email protected]> | 2020-06-27 15:09:29 +0100 |
commit | daf1cac9f87023d37a4418ea24ed615c9706258b (patch) | |
tree | d03541e3288316c2570bbc86a1b2bd97eea9292c /crates/ra_hir_ty/src/diagnostics.rs | |
parent | 0b95bed83fc8db897f54b350168567f14527e8de (diff) |
Move diagnostics back into expr, add tests for diagnostics, fix logic to account for derefs of raw ptrs
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 3469cc680..c6ca322fa 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -3,7 +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::{ast, AstNode, AstPtr, SyntaxNodePtr}; | 6 | use ra_syntax::{ast::{self, NameOwner}, AstNode, AstPtr, SyntaxNodePtr}; |
7 | use stdx::format_to; | 7 | use stdx::format_to; |
8 | 8 | ||
9 | pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; | 9 | pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm, path::Path}; |
@@ -174,12 +174,11 @@ impl AstDiagnostic for BreakOutsideOfLoop { | |||
174 | pub struct MissingUnsafe { | 174 | pub struct MissingUnsafe { |
175 | pub file: HirFileId, | 175 | pub file: HirFileId, |
176 | pub fn_def: AstPtr<ast::FnDef>, | 176 | pub fn_def: AstPtr<ast::FnDef>, |
177 | pub fn_name: Name, | ||
178 | } | 177 | } |
179 | 178 | ||
180 | impl Diagnostic for MissingUnsafe { | 179 | impl Diagnostic for MissingUnsafe { |
181 | fn message(&self) -> String { | 180 | fn message(&self) -> String { |
182 | format!("Missing unsafe marker on fn `{}`", self.fn_name) | 181 | format!("Missing unsafe keyword on fn") |
183 | } | 182 | } |
184 | fn source(&self) -> InFile<SyntaxNodePtr> { | 183 | fn source(&self) -> InFile<SyntaxNodePtr> { |
185 | InFile { file_id: self.file, value: self.fn_def.clone().into() } | 184 | InFile { file_id: self.file, value: self.fn_def.clone().into() } |
@@ -190,12 +189,12 @@ impl Diagnostic for MissingUnsafe { | |||
190 | } | 189 | } |
191 | 190 | ||
192 | impl AstDiagnostic for MissingUnsafe { | 191 | impl AstDiagnostic for MissingUnsafe { |
193 | type AST = ast::FnDef; | 192 | type AST = ast::Name; |
194 | 193 | ||
195 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { | 194 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { |
196 | let root = db.parse_or_expand(self.source().file_id).unwrap(); | 195 | let root = db.parse_or_expand(self.source().file_id).unwrap(); |
197 | let node = self.source().value.to_node(&root); | 196 | let node = self.source().value.to_node(&root); |
198 | ast::FnDef::cast(node).unwrap() | 197 | ast::FnDef::cast(node).unwrap().name().unwrap() |
199 | } | 198 | } |
200 | } | 199 | } |
201 | 200 | ||
@@ -203,12 +202,11 @@ impl AstDiagnostic for MissingUnsafe { | |||
203 | pub struct UnnecessaryUnsafe { | 202 | pub struct UnnecessaryUnsafe { |
204 | pub file: HirFileId, | 203 | pub file: HirFileId, |
205 | pub fn_def: AstPtr<ast::FnDef>, | 204 | pub fn_def: AstPtr<ast::FnDef>, |
206 | pub fn_name: Name, | ||
207 | } | 205 | } |
208 | 206 | ||
209 | impl Diagnostic for UnnecessaryUnsafe { | 207 | impl Diagnostic for UnnecessaryUnsafe { |
210 | fn message(&self) -> String { | 208 | fn message(&self) -> String { |
211 | format!("Unnecessary unsafe marker on fn `{}`", self.fn_name) | 209 | format!("Unnecessary unsafe keyword on fn") |
212 | } | 210 | } |
213 | fn source(&self) -> InFile<SyntaxNodePtr> { | 211 | fn source(&self) -> InFile<SyntaxNodePtr> { |
214 | InFile { file_id: self.file, value: self.fn_def.clone().into() } | 212 | InFile { file_id: self.file, value: self.fn_def.clone().into() } |
@@ -219,11 +217,11 @@ impl Diagnostic for UnnecessaryUnsafe { | |||
219 | } | 217 | } |
220 | 218 | ||
221 | impl AstDiagnostic for UnnecessaryUnsafe { | 219 | impl AstDiagnostic for UnnecessaryUnsafe { |
222 | type AST = ast::FnDef; | 220 | type AST = ast::Name; |
223 | 221 | ||
224 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { | 222 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { |
225 | let root = db.parse_or_expand(self.source().file_id).unwrap(); | 223 | let root = db.parse_or_expand(self.source().file_id).unwrap(); |
226 | let node = self.source().value.to_node(&root); | 224 | let node = self.source().value.to_node(&root); |
227 | ast::FnDef::cast(node).unwrap() | 225 | ast::FnDef::cast(node).unwrap().name().unwrap() |
228 | } | 226 | } |
229 | } | 227 | } |