From 86b7861612ba074120dfb6bd32c80c569688748d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 8 Apr 2021 20:43:07 +0200 Subject: Use named fields in `MacroCallKind` --- crates/hir_def/src/lib.rs | 9 +++++++-- crates/hir_def/src/nameres.rs | 28 ++++++++++++++-------------- crates/hir_def/src/nameres/collector.rs | 2 +- 3 files changed, 22 insertions(+), 17 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index e2af0e514..b72884925 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs @@ -690,7 +690,9 @@ fn macro_call_as_call_id( ) .map(MacroCallId::from) } else { - Ok(def.as_lazy_macro(db.upcast(), krate, MacroCallKind::FnLike(call.ast_id)).into()) + Ok(def + .as_lazy_macro(db.upcast(), krate, MacroCallKind::FnLike { ast_id: call.ast_id }) + .into()) }; Ok(res) } @@ -707,7 +709,10 @@ fn derive_macro_as_call_id( .as_lazy_macro( db.upcast(), krate, - MacroCallKind::Derive(item_attr.ast_id, last_segment.to_string()), + MacroCallKind::Derive { + ast_id: item_attr.ast_id, + derive_name: last_segment.to_string(), + }, ) .into(); Ok(res) diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 7dd68219f..d966fc239 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -613,12 +613,12 @@ mod diagnostics { DiagnosticKind::UnresolvedProcMacro { ast } => { let mut precise_location = None; let (file, ast, name) = match ast { - MacroCallKind::FnLike(ast) => { - let node = ast.to_node(db.upcast()); - (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None) + MacroCallKind::FnLike { ast_id } => { + let node = ast_id.to_node(db.upcast()); + (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None) } - MacroCallKind::Derive(ast, name) => { - let node = ast.to_node(db.upcast()); + MacroCallKind::Derive { ast_id, derive_name } => { + let node = ast_id.to_node(db.upcast()); // Compute the precise location of the macro name's token in the derive // list. @@ -639,7 +639,7 @@ mod diagnostics { }); for token in tokens { if token.kind() == SyntaxKind::IDENT - && token.text() == name.as_str() + && token.text() == derive_name.as_str() { precise_location = Some(token.text_range()); break 'outer; @@ -648,9 +648,9 @@ mod diagnostics { } ( - ast.file_id, + ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), - Some(name.clone()), + Some(derive_name.clone()), ) } }; @@ -669,13 +669,13 @@ mod diagnostics { DiagnosticKind::MacroError { ast, message } => { let (file, ast) = match ast { - MacroCallKind::FnLike(ast) => { - let node = ast.to_node(db.upcast()); - (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) + MacroCallKind::FnLike { ast_id, .. } => { + let node = ast_id.to_node(db.upcast()); + (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) } - MacroCallKind::Derive(ast, _) => { - let node = ast.to_node(db.upcast()); - (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) + MacroCallKind::Derive { ast_id, .. } => { + let node = ast_id.to_node(db.upcast()); + (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) } }; sink.push(MacroError { file, node: ast, message: message.clone() }); diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 6dbbe2d05..f431da3f2 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -1520,7 +1520,7 @@ impl ModCollector<'_, '_> { // Built-in macro failed eager expansion. self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error( self.module_id, - MacroCallKind::FnLike(ast_id.ast_id), + MacroCallKind::FnLike { ast_id: ast_id.ast_id }, error.unwrap().to_string(), )); return; -- cgit v1.2.3