diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-31 13:34:01 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-31 13:34:01 +0100 |
commit | b8d269990c57634e77f4702afc91041bacb4816a (patch) | |
tree | f1d707daa5f4d20abec75299234552b320fa1a42 /crates/hir | |
parent | d7cbb49057c4495307d91f5db32465c29c175124 (diff) | |
parent | cb5454db86bae1e97d86b05607b5c36a89fb749b (diff) |
Merge #9060
9060: feat: Diagnose unimplemented built-in macros r=matklad a=jonas-schievink
A number of built-in attribute macros are unsupported, I thought it might be useful to put a diagnostic on their definition in libcore. Not sure.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/diagnostics.rs | 24 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 12 |
2 files changed, 34 insertions, 2 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 22ec7c6ac..2cdbd172a 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -227,3 +227,27 @@ impl Diagnostic for MacroError { | |||
227 | true | 227 | true |
228 | } | 228 | } |
229 | } | 229 | } |
230 | |||
231 | #[derive(Debug)] | ||
232 | pub struct UnimplementedBuiltinMacro { | ||
233 | pub file: HirFileId, | ||
234 | pub node: SyntaxNodePtr, | ||
235 | } | ||
236 | |||
237 | impl Diagnostic for UnimplementedBuiltinMacro { | ||
238 | fn code(&self) -> DiagnosticCode { | ||
239 | DiagnosticCode("unimplemented-builtin-macro") | ||
240 | } | ||
241 | |||
242 | fn message(&self) -> String { | ||
243 | "unimplemented built-in macro".to_string() | ||
244 | } | ||
245 | |||
246 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
247 | InFile::new(self.file, self.node.clone()) | ||
248 | } | ||
249 | |||
250 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
251 | self | ||
252 | } | ||
253 | } | ||
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 975ae4869..d3ef29db4 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -36,8 +36,8 @@ use std::{iter, sync::Arc}; | |||
36 | use arrayvec::ArrayVec; | 36 | use arrayvec::ArrayVec; |
37 | use base_db::{CrateDisplayName, CrateId, Edition, FileId}; | 37 | use base_db::{CrateDisplayName, CrateId, Edition, FileId}; |
38 | use diagnostics::{ | 38 | use diagnostics::{ |
39 | InactiveCode, MacroError, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, | 39 | InactiveCode, MacroError, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, |
40 | UnresolvedModule, UnresolvedProcMacro, | 40 | UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro, |
41 | }; | 41 | }; |
42 | use either::Either; | 42 | use either::Either; |
43 | use hir_def::{ | 43 | use hir_def::{ |
@@ -565,6 +565,14 @@ impl Module { | |||
565 | }; | 565 | }; |
566 | sink.push(MacroError { file, node: ast, message: message.clone() }); | 566 | sink.push(MacroError { file, node: ast, message: message.clone() }); |
567 | } | 567 | } |
568 | |||
569 | DefDiagnosticKind::UnimplementedBuiltinMacro { ast } => { | ||
570 | let node = ast.to_node(db.upcast()); | ||
571 | // Must have a name, otherwise we wouldn't emit it. | ||
572 | let name = node.name().expect("unimplemented builtin macro with no name"); | ||
573 | let ptr = SyntaxNodePtr::from(AstPtr::new(&name)); | ||
574 | sink.push(UnimplementedBuiltinMacro { file: ast.file_id, node: ptr }); | ||
575 | } | ||
568 | } | 576 | } |
569 | } | 577 | } |
570 | for decl in self.declarations(db) { | 578 | for decl in self.declarations(db) { |