From d3621eeb02652038a8185f60d78fb4791a732dc6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 19:35:30 +0300 Subject: internal: refactor unimplemented builtin macro diagnostic --- crates/hir/src/diagnostics.rs | 30 ++++++------------------------ crates/hir/src/lib.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 26 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 28580eeb4..3908e67a2 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -32,14 +32,15 @@ macro_rules! diagnostics { } diagnostics![ - UnresolvedModule, + InactiveCode, + MacroError, + MissingFields, + UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, + UnresolvedModule, UnresolvedProcMacro, - MacroError, - MissingFields, - InactiveCode, ]; #[derive(Debug)] @@ -88,26 +89,7 @@ pub struct MacroError { #[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 - } + pub node: InFile, } // Diagnostic: no-such-field diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d891d0ec1..a361158e0 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -606,8 +606,12 @@ impl Module { 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 }); + acc.push( + UnimplementedBuiltinMacro { + node: ast.with_value(SyntaxNodePtr::from(AstPtr::new(&name))), + } + .into(), + ); } } } -- cgit v1.2.3