diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-21 15:21:11 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-21 15:21:11 +0000 |
commit | 5bb65bb4962cfad613e9744a340ae23b533f479e (patch) | |
tree | 0bc7d77dbdfea452840d47d5c1fbd67092ab10f2 /crates | |
parent | 0d40ff5e623b3670ce3e0e324ecbab3e5197aaeb (diff) | |
parent | 5322cd830eba39c66650a995af7006c2ef16f925 (diff) |
Merge #8128
8128: Expand legacy-scoped macro during collection r=jonas-schievink a=jonas-schievink
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8120
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 13 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests/macros.rs | 21 |
2 files changed, 28 insertions, 6 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 46a3c60cd..28b73c3a1 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1467,12 +1467,13 @@ impl ModCollector<'_, '_> { | |||
1467 | }, | 1467 | }, |
1468 | ) { | 1468 | ) { |
1469 | Ok(Ok(macro_call_id)) => { | 1469 | Ok(Ok(macro_call_id)) => { |
1470 | self.def_collector.unexpanded_macros.push(MacroDirective { | 1470 | // Legacy macros need to be expanded immediately, so that any macros they produce |
1471 | module_id: self.module_id, | 1471 | // are in scope. |
1472 | ast_id, | 1472 | self.def_collector.collect_macro_expansion( |
1473 | legacy: Some(macro_call_id), | 1473 | self.module_id, |
1474 | depth: self.macro_depth + 1, | 1474 | macro_call_id, |
1475 | }); | 1475 | self.macro_depth + 1, |
1476 | ); | ||
1476 | 1477 | ||
1477 | return; | 1478 | return; |
1478 | } | 1479 | } |
diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index d59d3c0db..6d3cb8d7a 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs | |||
@@ -713,6 +713,27 @@ b! { static = #[] ();} | |||
713 | } | 713 | } |
714 | 714 | ||
715 | #[test] | 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 | |||
736 | #[test] | ||
716 | fn resolves_proc_macros() { | 737 | fn resolves_proc_macros() { |
717 | check( | 738 | check( |
718 | r" | 739 | r" |