diff options
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index ebd9cb08f..3469cc680 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -169,3 +169,61 @@ impl AstDiagnostic for BreakOutsideOfLoop { | |||
169 | ast::Expr::cast(node).unwrap() | 169 | ast::Expr::cast(node).unwrap() |
170 | } | 170 | } |
171 | } | 171 | } |
172 | |||
173 | #[derive(Debug)] | ||
174 | pub struct MissingUnsafe { | ||
175 | pub file: HirFileId, | ||
176 | pub fn_def: AstPtr<ast::FnDef>, | ||
177 | pub fn_name: Name, | ||
178 | } | ||
179 | |||
180 | impl Diagnostic for MissingUnsafe { | ||
181 | fn message(&self) -> String { | ||
182 | format!("Missing unsafe marker on fn `{}`", self.fn_name) | ||
183 | } | ||
184 | fn source(&self) -> InFile<SyntaxNodePtr> { | ||
185 | InFile { file_id: self.file, value: self.fn_def.clone().into() } | ||
186 | } | ||
187 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
188 | self | ||
189 | } | ||
190 | } | ||
191 | |||
192 | impl AstDiagnostic for MissingUnsafe { | ||
193 | type AST = ast::FnDef; | ||
194 | |||
195 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { | ||
196 | let root = db.parse_or_expand(self.source().file_id).unwrap(); | ||
197 | let node = self.source().value.to_node(&root); | ||
198 | ast::FnDef::cast(node).unwrap() | ||
199 | } | ||
200 | } | ||
201 | |||
202 | #[derive(Debug)] | ||
203 | pub struct UnnecessaryUnsafe { | ||
204 | pub file: HirFileId, | ||
205 | pub fn_def: AstPtr<ast::FnDef>, | ||
206 | pub fn_name: Name, | ||
207 | } | ||
208 | |||
209 | impl Diagnostic for UnnecessaryUnsafe { | ||
210 | fn message(&self) -> String { | ||
211 | format!("Unnecessary unsafe marker on fn `{}`", self.fn_name) | ||
212 | } | ||
213 | fn source(&self) -> InFile<SyntaxNodePtr> { | ||
214 | InFile { file_id: self.file, value: self.fn_def.clone().into() } | ||
215 | } | ||
216 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
217 | self | ||
218 | } | ||
219 | } | ||
220 | |||
221 | impl AstDiagnostic for UnnecessaryUnsafe { | ||
222 | type AST = ast::FnDef; | ||
223 | |||
224 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { | ||
225 | let root = db.parse_or_expand(self.source().file_id).unwrap(); | ||
226 | let node = self.source().value.to_node(&root); | ||
227 | ast::FnDef::cast(node).unwrap() | ||
228 | } | ||
229 | } | ||