Skip to content

Commit 5bb65bb

Browse files
Merge #8128
8128: Expand legacy-scoped macro during collection r=jonas-schievink a=jonas-schievink Fixes #8120 Co-authored-by: Jonas Schievink <[email protected]>
2 parents 0d40ff5 + 5322cd8 commit 5bb65bb

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

crates/hir_def/src/nameres/collector.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,12 +1467,13 @@ impl ModCollector<'_, '_> {
14671467
},
14681468
) {
14691469
Ok(Ok(macro_call_id)) => {
1470-
self.def_collector.unexpanded_macros.push(MacroDirective {
1471-
module_id: self.module_id,
1472-
ast_id,
1473-
legacy: Some(macro_call_id),
1474-
depth: self.macro_depth + 1,
1475-
});
1470+
// Legacy macros need to be expanded immediately, so that any macros they produce
1471+
// are in scope.
1472+
self.def_collector.collect_macro_expansion(
1473+
self.module_id,
1474+
macro_call_id,
1475+
self.macro_depth + 1,
1476+
);
14761477

14771478
return;
14781479
}

crates/hir_def/src/nameres/tests/macros.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,27 @@ b! { static = #[] ();}
712712
);
713713
}
714714

715+
#[test]
716+
fn macros_defining_macros() {
717+
check(
718+
r#"
719+
macro_rules! item {
720+
($item:item) => { $item }
721+
}
722+
723+
item! {
724+
macro_rules! indirect_macro { () => { struct S {} } }
725+
}
726+
727+
indirect_macro!();
728+
"#,
729+
expect![[r#"
730+
crate
731+
S: t
732+
"#]],
733+
);
734+
}
735+
715736
#[test]
716737
fn resolves_proc_macros() {
717738
check(

0 commit comments

Comments
 (0)