From cb5454db86bae1e97d86b05607b5c36a89fb749b Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 30 May 2021 04:19:47 +0200 Subject: Diagnose unimplemented built-in macros --- crates/hir/src/diagnostics.rs | 24 ++++++++++++++++++++++++ crates/hir/src/lib.rs | 12 ++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'crates/hir') 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 { true } } + +#[derive(Debug)] +pub struct UnimplementedBuiltinMacro { + pub file: HirFileId, + pub node: SyntaxNodePtr, +} + +impl Diagnostic for UnimplementedBuiltinMacro { + fn code(&self) -> DiagnosticCode { + DiagnosticCode("unimplemented-builtin-macro") + } + + fn message(&self) -> String { + "unimplemented built-in macro".to_string() + } + + fn display_source(&self) -> InFile { + InFile::new(self.file, self.node.clone()) + } + + fn as_any(&self) -> &(dyn Any + Send + 'static) { + self + } +} 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}; use arrayvec::ArrayVec; use base_db::{CrateDisplayName, CrateId, Edition, FileId}; use diagnostics::{ - InactiveCode, MacroError, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, - UnresolvedModule, UnresolvedProcMacro, + InactiveCode, MacroError, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, + UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro, }; use either::Either; use hir_def::{ @@ -565,6 +565,14 @@ impl Module { }; sink.push(MacroError { file, node: ast, message: message.clone() }); } + + DefDiagnosticKind::UnimplementedBuiltinMacro { ast } => { + let node = ast.to_node(db.upcast()); + // Must have a name, otherwise we wouldn't emit it. + let name = node.name().expect("unimplemented builtin macro with no name"); + let ptr = SyntaxNodePtr::from(AstPtr::new(&name)); + sink.push(UnimplementedBuiltinMacro { file: ast.file_id, node: ptr }); + } } } for decl in self.declarations(db) { -- cgit v1.2.3