From e0f305a6bf710f64f789f909da93a8c362823b67 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Sat, 7 Sep 2019 00:55:58 +0800 Subject: Support textual scoped macros --- crates/ra_hir/src/nameres/tests/macros.rs | 91 +++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'crates/ra_hir/src/nameres/tests/macros.rs') diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index c62152d26..8f0db95f2 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -277,3 +277,94 @@ fn prelude_cycle() { ⋮crate::foo "###); } + +#[test] +fn plain_macros_are_textual_scoped_between_modules() { + let map = def_map( + r#" + //- /main.rs + mod m1; + bar!(NotFoundNotMacroUse); + + mod m2 { + foo!(NotFoundBeforeInside2); + } + + macro_rules! foo { + ($x:ident) => { struct $x; } + } + foo!(Ok); + + mod m3; + foo!(OkShadowStop); + bar!(NotFoundMacroUseStop); + + #[macro_use] + mod m5 { + #[macro_use] + mod m6 { + macro_rules! foo { + ($x:ident) => { fn $x() {} } + } + } + } + foo!(ok_double_macro_use_shadow); + + //- /m1.rs + foo!(NotFoundBeforeInside1); + macro_rules! bar { + ($x:ident) => { struct $x; } + } + + //- /m3/mod.rs + foo!(OkAfterInside); + macro_rules! foo { + ($x:ident) => { fn $x() {} } + } + foo!(ok_shadow); + + #[macro_use] + mod m4; + bar!(OkMacroUse); + + //- /m3/m4.rs + foo!(ok_shadow_deep); + macro_rules! bar { + ($x:ident) => { struct $x; } + } + "#, + ); + assert_snapshot!(map, @r###" + ⋮crate + ⋮Ok: t v + ⋮OkShadowStop: t v + ⋮foo: m + ⋮m1: t + ⋮m2: t + ⋮m3: t + ⋮m5: t + ⋮ok_double_macro_use_shadow: v + ⋮ + ⋮crate::m1 + ⋮bar: m + ⋮ + ⋮crate::m5 + ⋮m6: t + ⋮ + ⋮crate::m5::m6 + ⋮foo: m + ⋮ + ⋮crate::m2 + ⋮ + ⋮crate::m3 + ⋮OkAfterInside: t v + ⋮OkMacroUse: t v + ⋮foo: m + ⋮m4: t + ⋮ok_shadow: v + ⋮ + ⋮crate::m3::m4 + ⋮bar: m + ⋮ok_shadow_deep: v + "###); +} -- cgit v1.2.3 From 26b092bd3b431559d7aafbf42882f978c0bb3dab Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Sat, 7 Sep 2019 02:44:26 +0800 Subject: Resolve textual scoped macros inside item --- crates/ra_hir/src/nameres/tests/macros.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/nameres/tests/macros.rs') diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index 8f0db95f2..a894c6836 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -279,7 +279,7 @@ fn prelude_cycle() { } #[test] -fn plain_macros_are_textual_scoped_between_modules() { +fn plain_macros_are_textual_scoped() { let map = def_map( r#" //- /main.rs @@ -310,6 +310,15 @@ fn plain_macros_are_textual_scoped_between_modules() { } foo!(ok_double_macro_use_shadow); + baz!(NotFoundBefore); + #[macro_use] + mod m7 { + macro_rules! baz { + ($x:ident) => { struct $x; } + } + } + baz!(OkAfter); + //- /m1.rs foo!(NotFoundBeforeInside1); macro_rules! bar { @@ -337,14 +346,19 @@ fn plain_macros_are_textual_scoped_between_modules() { assert_snapshot!(map, @r###" ⋮crate ⋮Ok: t v + ⋮OkAfter: t v ⋮OkShadowStop: t v ⋮foo: m ⋮m1: t ⋮m2: t ⋮m3: t ⋮m5: t + ⋮m7: t ⋮ok_double_macro_use_shadow: v ⋮ + ⋮crate::m7 + ⋮baz: m + ⋮ ⋮crate::m1 ⋮bar: m ⋮ -- cgit v1.2.3 From 92c07803cc0ce1d2008cc912f006d1cd66ff3f4a Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Sun, 8 Sep 2019 00:37:54 +0800 Subject: Rename `textual_macro` -> `legacy_macro` Add comments --- crates/ra_hir/src/nameres/tests/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir/src/nameres/tests/macros.rs') diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index a894c6836..21fab53e9 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -279,7 +279,7 @@ fn prelude_cycle() { } #[test] -fn plain_macros_are_textual_scoped() { +fn plain_macros_are_legacy_textual_scoped() { let map = def_map( r#" //- /main.rs -- cgit v1.2.3 From 9ed21d65fb6727f6de4961dfa440981864451af6 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Sun, 8 Sep 2019 03:40:04 +0800 Subject: Fix test --- crates/ra_hir/src/nameres/tests/macros.rs | 3 --- 1 file changed, 3 deletions(-) (limited to 'crates/ra_hir/src/nameres/tests/macros.rs') diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index 21fab53e9..ebc4d6890 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -268,13 +268,10 @@ fn prelude_cycle() { ); assert_snapshot!(map, @r###" ⋮crate - ⋮foo: t ⋮prelude: t ⋮ ⋮crate::prelude ⋮declare_mod: m - ⋮ - ⋮crate::foo "###); } -- cgit v1.2.3