From 00303284b5cc3a82e32dc3ecbbcfeb2f99de6818 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 18:41:04 +0300 Subject: internal: refactor macro error --- crates/hir/src/lib.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'crates/hir/src/lib.rs') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 87a3db946..d891d0ec1 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -587,19 +587,19 @@ impl Module { } DefDiagnosticKind::MacroError { ast, message } => { - let (file, ast) = match ast { + let node = match ast { MacroCallKind::FnLike { ast_id, .. } => { let node = ast_id.to_node(db.upcast()); - (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) + ast_id.with_value(SyntaxNodePtr::from(AstPtr::new(&node))) } MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => { // FIXME: point to the attribute instead, this creates very large diagnostics let node = ast_id.to_node(db.upcast()); - (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) + ast_id.with_value(SyntaxNodePtr::from(AstPtr::new(&node))) } }; - sink.push(MacroError { file, node: ast, message: message.clone() }); + acc.push(MacroError { node, message: message.clone() }.into()); } DefDiagnosticKind::UnimplementedBuiltinMacro { ast } => { @@ -1046,11 +1046,13 @@ impl Function { InactiveCode { node: node.clone(), cfg: cfg.clone(), opts: opts.clone() } .into(), ), - BodyDiagnostic::MacroError { node, message } => sink.push(MacroError { - file: node.file_id, - node: node.value.clone().into(), - message: message.to_string(), - }), + BodyDiagnostic::MacroError { node, message } => acc.push( + MacroError { + node: node.clone().map(|it| it.into()), + message: message.to_string(), + } + .into(), + ), BodyDiagnostic::UnresolvedProcMacro { node } => acc.push( UnresolvedProcMacro { node: node.clone().map(|it| it.into()), -- cgit v1.2.3