Skip to content

Commit 51e5316

Browse files
Merge #8428
8428: Use named fields in `MacroCallKind` r=jonas-schievink a=jonas-schievink bors r+ changelog skip Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2 parents 5f279d5 + 86b7861 commit 51e5316

File tree

7 files changed

+40
-33
lines changed

7 files changed

+40
-33
lines changed

crates/hir_def/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,9 @@ fn macro_call_as_call_id(
690690
)
691691
.map(MacroCallId::from)
692692
} else {
693-
Ok(def.as_lazy_macro(db.upcast(), krate, MacroCallKind::FnLike(call.ast_id)).into())
693+
Ok(def
694+
.as_lazy_macro(db.upcast(), krate, MacroCallKind::FnLike { ast_id: call.ast_id })
695+
.into())
694696
};
695697
Ok(res)
696698
}
@@ -707,7 +709,10 @@ fn derive_macro_as_call_id(
707709
.as_lazy_macro(
708710
db.upcast(),
709711
krate,
710-
MacroCallKind::Derive(item_attr.ast_id, last_segment.to_string()),
712+
MacroCallKind::Derive {
713+
ast_id: item_attr.ast_id,
714+
derive_name: last_segment.to_string(),
715+
},
711716
)
712717
.into();
713718
Ok(res)

crates/hir_def/src/nameres.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,12 @@ mod diagnostics {
613613
DiagnosticKind::UnresolvedProcMacro { ast } => {
614614
let mut precise_location = None;
615615
let (file, ast, name) = match ast {
616-
MacroCallKind::FnLike(ast) => {
617-
let node = ast.to_node(db.upcast());
618-
(ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None)
616+
MacroCallKind::FnLike { ast_id } => {
617+
let node = ast_id.to_node(db.upcast());
618+
(ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None)
619619
}
620-
MacroCallKind::Derive(ast, name) => {
621-
let node = ast.to_node(db.upcast());
620+
MacroCallKind::Derive { ast_id, derive_name } => {
621+
let node = ast_id.to_node(db.upcast());
622622

623623
// Compute the precise location of the macro name's token in the derive
624624
// list.
@@ -639,7 +639,7 @@ mod diagnostics {
639639
});
640640
for token in tokens {
641641
if token.kind() == SyntaxKind::IDENT
642-
&& token.text() == name.as_str()
642+
&& token.text() == derive_name.as_str()
643643
{
644644
precise_location = Some(token.text_range());
645645
break 'outer;
@@ -648,9 +648,9 @@ mod diagnostics {
648648
}
649649

650650
(
651-
ast.file_id,
651+
ast_id.file_id,
652652
SyntaxNodePtr::from(AstPtr::new(&node)),
653-
Some(name.clone()),
653+
Some(derive_name.clone()),
654654
)
655655
}
656656
};
@@ -669,13 +669,13 @@ mod diagnostics {
669669

670670
DiagnosticKind::MacroError { ast, message } => {
671671
let (file, ast) = match ast {
672-
MacroCallKind::FnLike(ast) => {
673-
let node = ast.to_node(db.upcast());
674-
(ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node)))
672+
MacroCallKind::FnLike { ast_id, .. } => {
673+
let node = ast_id.to_node(db.upcast());
674+
(ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)))
675675
}
676-
MacroCallKind::Derive(ast, _) => {
677-
let node = ast.to_node(db.upcast());
678-
(ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node)))
676+
MacroCallKind::Derive { ast_id, .. } => {
677+
let node = ast_id.to_node(db.upcast());
678+
(ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)))
679679
}
680680
};
681681
sink.push(MacroError { file, node: ast, message: message.clone() });

crates/hir_def/src/nameres/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ impl ModCollector<'_, '_> {
15201520
// Built-in macro failed eager expansion.
15211521
self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error(
15221522
self.module_id,
1523-
MacroCallKind::FnLike(ast_id.ast_id),
1523+
MacroCallKind::FnLike { ast_id: ast_id.ast_id },
15241524
error.unwrap().to_string(),
15251525
));
15261526
return;

crates/hir_expand/src/builtin_derive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ $0
308308

309309
let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap();
310310

311-
let attr_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0]));
311+
let ast_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0]));
312312

313313
let loc = MacroCallLoc {
314314
def: MacroDefId {
@@ -317,7 +317,7 @@ $0
317317
local_inner: false,
318318
},
319319
krate: CrateId(0),
320-
kind: MacroCallKind::Derive(attr_id, name.to_string()),
320+
kind: MacroCallKind::Derive { ast_id, derive_name: name.to_string() },
321321
};
322322

323323
let id: MacroCallId = db.intern_macro(loc).into();

crates/hir_expand/src/builtin_macro.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,9 @@ mod tests {
566566
let loc = MacroCallLoc {
567567
def,
568568
krate,
569-
kind: MacroCallKind::FnLike(AstId::new(
570-
file_id.into(),
571-
ast_id_map.ast_id(&macro_call),
572-
)),
569+
kind: MacroCallKind::FnLike {
570+
ast_id: AstId::new(file_id.into(), ast_id_map.ast_id(&macro_call)),
571+
},
573572
};
574573

575574
let id: MacroCallId = db.intern_macro(loc).into();

crates/hir_expand/src/eager.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ fn lazy_expand(
174174
) -> ExpandResult<Option<InFile<SyntaxNode>>> {
175175
let ast_id = db.ast_id_map(macro_call.file_id).ast_id(&macro_call.value);
176176

177-
let id: MacroCallId =
178-
def.as_lazy_macro(db, krate, MacroCallKind::FnLike(macro_call.with_value(ast_id))).into();
177+
let id: MacroCallId = def
178+
.as_lazy_macro(db, krate, MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id) })
179+
.into();
179180

180181
let err = db.macro_expand_error(id);
181182
let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node));

crates/hir_expand/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,33 +290,35 @@ pub struct MacroCallLoc {
290290

291291
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
292292
pub enum MacroCallKind {
293-
FnLike(AstId<ast::MacroCall>),
294-
Derive(AstId<ast::Item>, String),
293+
FnLike { ast_id: AstId<ast::MacroCall> },
294+
Derive { ast_id: AstId<ast::Item>, derive_name: String },
295295
}
296296

297297
impl MacroCallKind {
298298
fn file_id(&self) -> HirFileId {
299299
match self {
300-
MacroCallKind::FnLike(ast_id) => ast_id.file_id,
301-
MacroCallKind::Derive(ast_id, _) => ast_id.file_id,
300+
MacroCallKind::FnLike { ast_id, .. } => ast_id.file_id,
301+
MacroCallKind::Derive { ast_id, .. } => ast_id.file_id,
302302
}
303303
}
304304

305305
fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> {
306306
match self {
307-
MacroCallKind::FnLike(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()),
308-
MacroCallKind::Derive(ast_id, _) => {
307+
MacroCallKind::FnLike { ast_id, .. } => {
308+
ast_id.with_value(ast_id.to_node(db).syntax().clone())
309+
}
310+
MacroCallKind::Derive { ast_id, .. } => {
309311
ast_id.with_value(ast_id.to_node(db).syntax().clone())
310312
}
311313
}
312314
}
313315

314316
fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> {
315317
match self {
316-
MacroCallKind::FnLike(ast_id) => {
318+
MacroCallKind::FnLike { ast_id, .. } => {
317319
Some(ast_id.to_node(db).token_tree()?.syntax().clone())
318320
}
319-
MacroCallKind::Derive(ast_id, _) => Some(ast_id.to_node(db).syntax().clone()),
321+
MacroCallKind::Derive { ast_id, .. } => Some(ast_id.to_node(db).syntax().clone()),
320322
}
321323
}
322324
}

0 commit comments

Comments
 (0)