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_expand/src/builtin_derive.rs | 4 ++-- crates/hir_expand/src/builtin_macro.rs | 7 +++---- crates/hir_expand/src/eager.rs | 5 +++-- crates/hir_expand/src/lib.rs | 18 ++++++++++-------- 4 files changed, 18 insertions(+), 16 deletions(-) (limited to 'crates/hir_expand') diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs index 6ece4b289..392079ed4 100644 --- a/crates/hir_expand/src/builtin_derive.rs +++ b/crates/hir_expand/src/builtin_derive.rs @@ -308,7 +308,7 @@ $0 let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap(); - let attr_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0])); + let ast_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0])); let loc = MacroCallLoc { def: MacroDefId { @@ -317,7 +317,7 @@ $0 local_inner: false, }, krate: CrateId(0), - kind: MacroCallKind::Derive(attr_id, name.to_string()), + kind: MacroCallKind::Derive { ast_id, derive_name: name.to_string() }, }; let id: MacroCallId = db.intern_macro(loc).into(); diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index a7d0f5b1f..80365fc16 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -566,10 +566,9 @@ mod tests { let loc = MacroCallLoc { def, krate, - kind: MacroCallKind::FnLike(AstId::new( - file_id.into(), - ast_id_map.ast_id(¯o_call), - )), + kind: MacroCallKind::FnLike { + ast_id: AstId::new(file_id.into(), ast_id_map.ast_id(¯o_call)), + }, }; let id: MacroCallId = db.intern_macro(loc).into(); diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index 9705526fa..ef126e4ad 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs @@ -174,8 +174,9 @@ fn lazy_expand( ) -> ExpandResult>> { let ast_id = db.ast_id_map(macro_call.file_id).ast_id(¯o_call.value); - let id: MacroCallId = - def.as_lazy_macro(db, krate, MacroCallKind::FnLike(macro_call.with_value(ast_id))).into(); + let id: MacroCallId = def + .as_lazy_macro(db, krate, MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id) }) + .into(); let err = db.macro_expand_error(id); let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node)); diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index 3e332ee47..a179102f0 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs @@ -290,22 +290,24 @@ pub struct MacroCallLoc { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum MacroCallKind { - FnLike(AstId), - Derive(AstId, String), + FnLike { ast_id: AstId }, + Derive { ast_id: AstId, derive_name: String }, } impl MacroCallKind { fn file_id(&self) -> HirFileId { match self { - MacroCallKind::FnLike(ast_id) => ast_id.file_id, - MacroCallKind::Derive(ast_id, _) => ast_id.file_id, + MacroCallKind::FnLike { ast_id, .. } => ast_id.file_id, + MacroCallKind::Derive { ast_id, .. } => ast_id.file_id, } } fn node(&self, db: &dyn db::AstDatabase) -> InFile { match self { - MacroCallKind::FnLike(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()), - MacroCallKind::Derive(ast_id, _) => { + MacroCallKind::FnLike { ast_id, .. } => { + ast_id.with_value(ast_id.to_node(db).syntax().clone()) + } + MacroCallKind::Derive { ast_id, .. } => { ast_id.with_value(ast_id.to_node(db).syntax().clone()) } } @@ -313,10 +315,10 @@ impl MacroCallKind { fn arg(&self, db: &dyn db::AstDatabase) -> Option { match self { - MacroCallKind::FnLike(ast_id) => { + MacroCallKind::FnLike { ast_id, .. } => { Some(ast_id.to_node(db).token_tree()?.syntax().clone()) } - MacroCallKind::Derive(ast_id, _) => Some(ast_id.to_node(db).syntax().clone()), + MacroCallKind::Derive { ast_id, .. } => Some(ast_id.to_node(db).syntax().clone()), } } } -- cgit v1.2.3