Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/tests/macros.rs')
-rw-r--r--crates/hir-def/src/nameres/tests/macros.rs523
1 files changed, 354 insertions, 169 deletions
diff --git a/crates/hir-def/src/nameres/tests/macros.rs b/crates/hir-def/src/nameres/tests/macros.rs
index 3cba88ec2f..a943f6f0ac 100644
--- a/crates/hir-def/src/nameres/tests/macros.rs
+++ b/crates/hir-def/src/nameres/tests/macros.rs
@@ -23,12 +23,14 @@ structs!(Bar, Baz);
"#,
expect![[r#"
crate
- Foo: t
- nested: t
+ - Foo : type
+ - nested : type
+ - (legacy) structs : macro!
crate::nested
- Bar: t
- Baz: t
+ - Bar : type
+ - Baz : type
+ - (legacy) structs : macro!
"#]],
);
}
@@ -53,20 +55,25 @@ struct Y;
"#,
expect![[r#"
crate
- m: t
- n1: t
+ - m : type
+ - n1 : type
+ - (legacy) m : macro!
crate::m
- n3: t
+ - n3 : type
+ - (legacy) m : macro!
crate::m::n3
- Y: t v
+ - Y : type value
+ - (legacy) m : macro!
crate::n1
- n2: t
+ - n2 : type
+ - (legacy) m : macro!
crate::n1::n2
- X: t v
+ - X : type value
+ - (legacy) m : macro!
"#]],
);
}
@@ -92,14 +99,14 @@ macro_rules! structs {
"#,
expect![[r#"
crate
- Bar: t
- Foo: t
- bar: t
+ - Bar : type
+ - Foo : type
+ - bar : type
crate::bar
- Bar: tg
- Foo: tg
- bar: tg
+ - Bar : type (glob)
+ - Foo : type (glob)
+ - bar : type (glob)
"#]],
);
}
@@ -125,14 +132,14 @@ macro_rules! structs {
"#,
expect![[r#"
crate
- Bar: t
- Foo: t
- bar: t
+ - Bar : type
+ - Foo : type
+ - bar : type
crate::bar
- Bar: tg
- Foo: tg
- bar: tg
+ - Bar : type (glob)
+ - Foo : type (glob)
+ - bar : type (glob)
"#]],
);
}
@@ -164,14 +171,14 @@ macro_rules! inner {
"#,
expect![[r#"
crate
- Bar: t
- Foo: t
- bar: t
+ - Bar : type
+ - Foo : type
+ - bar : type
crate::bar
- Bar: tg
- Foo: tg
- bar: tg
+ - Bar : type (glob)
+ - Foo : type (glob)
+ - bar : type (glob)
"#]],
);
}
@@ -206,9 +213,10 @@ macro_rules! bar {
"#,
expect![[r#"
crate
- Foo: t
- bar: mi
- foo: mi
+ - Foo : type
+ - bar : macro! (import)
+ - foo : macro! (import)
+ - (legacy) baz : macro!
"#]],
);
}
@@ -252,13 +260,13 @@ mod priv_mod {
"#,
expect![[r#"
crate
- Bar: t v
- Foo: t v
- bar: t
- foo: te
+ - Bar : type value
+ - Foo : type value
+ - bar : type
+ - foo : type (extern)
crate::bar
- Baz: t v
+ - Baz : type value
"#]],
);
}
@@ -316,15 +324,15 @@ macro_rules! baz3 { () => { struct OkBaz3; } }
"#,
expect![[r#"
crate
- OkBar1: t v
- OkBar2: t v
- OkBar3: t v
- OkBaz1: t v
- OkBaz2: t v
- OkBaz3: t v
- all: te
- empty: te
- multiple: te
+ - OkBar1 : type value
+ - OkBar2 : type value
+ - OkBar3 : type value
+ - OkBaz1 : type value
+ - OkBaz2 : type value
+ - OkBaz3 : type value
+ - all : type (extern)
+ - empty : type (extern)
+ - multiple : type (extern)
"#]],
);
}
@@ -370,13 +378,13 @@ macro_rules! structs_outside {
"#,
expect![[r#"
crate
- Bar: t v
- Foo: t v
- Out: t v
- bar: t
+ - Bar : type value
+ - Foo : type value
+ - Out : type value
+ - bar : type
crate::bar
- Baz: t v
+ - Baz : type value
"#]],
);
}
@@ -398,9 +406,10 @@ mod prelude {
"#,
expect![[r#"
crate
- prelude: t
+ - prelude : type
crate::prelude
+ - (legacy) declare_mod : macro!
"#]],
);
}
@@ -419,7 +428,8 @@ macro_rules! m {
"#,
expect![[r#"
crate
- S: t v
+ - S : type value
+ - (legacy) m : macro!
"#]],
);
// FIXME: should not expand. legacy macro scoping is not implemented.
@@ -499,40 +509,55 @@ macro_rules! baz {
"#,
expect![[r#"
crate
- NotFoundBefore: t v
- Ok: t v
- OkAfter: t v
- OkShadowStop: t v
- m1: t
- m2: t
- m3: t
- m5: t
- m7: t
- ok_double_macro_use_shadow: v
+ - NotFoundBefore : type value
+ - Ok : type value
+ - OkAfter : type value
+ - OkShadowStop : type value
+ - m1 : type
+ - m2 : type
+ - m3 : type
+ - m5 : type
+ - m7 : type
+ - ok_double_macro_use_shadow : value
+ - (legacy) baz : macro!
+ - (legacy) foo : macro! macro! macro!
crate::m1
+ - (legacy) bar : macro!
crate::m2
crate::m3
- OkAfterInside: t v
- OkMacroUse: t v
- OkMacroUseInner: t v
- m4: t
- m5: t
- ok_shadow: v
+ - OkAfterInside : type value
+ - OkMacroUse : type value
+ - OkMacroUseInner : type value
+ - m4 : type
+ - m5 : type
+ - ok_shadow : value
+ - (legacy) bar : macro! macro!
+ - (legacy) baz : macro!
+ - (legacy) foo : macro! macro! macro! macro!
crate::m3::m4
- ok_shadow_deep: v
+ - ok_shadow_deep : value
+ - (legacy) bar : macro!
+ - (legacy) foo : macro! macro!
crate::m3::m5
+ - (legacy) bar : macro!
+ - (legacy) baz : macro!
+ - (legacy) foo : macro! macro! macro!
crate::m5
- m6: t
+ - m6 : type
+ - (legacy) foo : macro! macro!
crate::m5::m6
+ - (legacy) foo : macro! macro!
crate::m7
+ - (legacy) baz : macro!
+ - (legacy) foo : macro! macro!
"#]],
);
// FIXME: should not see `NotFoundBefore`
@@ -555,9 +580,10 @@ fn baz() {}
"#,
expect![[r#"
crate
- bar: ti mi
- baz: ti v mi
- foo: t m
+ - bar : type (import) macro! (import)
+ - baz : type (import) value macro! (import)
+ - foo : type macro!
+ - (legacy) foo : macro!
"#]],
);
}
@@ -585,9 +611,9 @@ mod m {
"#,
expect![[r#"
crate
- Alias: t v
- Direct: t v
- foo: te
+ - Alias : type value
+ - Direct : type value
+ - foo : type (extern)
"#]],
);
}
@@ -623,19 +649,22 @@ mod m {
"#,
expect![[r#"
crate
- OkAliasCrate: t v
- OkAliasPlain: t v
- OkAliasSuper: t v
- OkCrate: t v
- OkPlain: t v
- bar: m
- m: t
+ - OkAliasCrate : type value
+ - OkAliasPlain : type value
+ - OkAliasSuper : type value
+ - OkCrate : type value
+ - OkPlain : type value
+ - bar : macro!
+ - m : type
+ - (legacy) foo : macro!
crate::m
- alias1: mi
- alias2: mi
- alias3: mi
- not_found: _
+ - alias1 : macro! (import)
+ - alias2 : macro! (import)
+ - alias3 : macro! (import)
+ - not_found : _
+ - (legacy) bar : macro!
+ - (legacy) foo : macro!
"#]],
);
}
@@ -686,14 +715,16 @@ pub struct Baz;
"#,
expect![[r#"
crate
- Bar: ti vi
- Baz: ti vi
- Foo: t v
- FooSelf: ti vi
- foo: te
- m: t
+ - Bar : type (import) value (import)
+ - Baz : type (import) value (import)
+ - Foo : type value
+ - FooSelf : type (import) value (import)
+ - foo : type (extern)
+ - m : type
+ - (legacy) current : macro!
crate::m
+ - (legacy) current : macro!
"#]],
);
}
@@ -729,7 +760,7 @@ pub struct bar;
"#,
expect![[r#"
crate
- bar: ti vi
+ - bar : type (import) value (import)
"#]],
);
}
@@ -753,7 +784,7 @@ macro_rules! foo {
pub use core::clone::Clone;
"#,
- |map| assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1),
+ |map| assert_eq!(map.modules[map.root].scope.builtin_derive_impls().len(), 1),
);
}
@@ -775,7 +806,7 @@ pub macro Copy {}
#[rustc_builtin_macro]
pub macro Clone {}
"#,
- |map| assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 2),
+ |map| assert_eq!(map.modules[map.root].scope.builtin_derive_impls().len(), 2),
);
}
@@ -794,7 +825,7 @@ pub trait Clone {}
"#,
expect![[r#"
crate
- Clone: tg mg
+ - Clone : type (glob) macro# (glob)
"#]],
);
}
@@ -818,7 +849,7 @@ pub macro derive($item:item) {}
#[rustc_builtin_macro]
pub macro Clone {}
"#,
- |map| assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1),
+ |map| assert_eq!(map.modules[map.root].scope.builtin_derive_impls().len(), 1),
);
}
@@ -842,11 +873,11 @@ fn unresolved_attributes_fall_back_track_per_file_moditems() {
"#,
expect![[r#"
crate
- Foo: t v
- submod: t
+ - Foo : type value
+ - submod : type
crate::submod
- Bar: t v
+ - Bar : type value
"#]],
);
}
@@ -863,9 +894,9 @@ extern "C" {
}
"#,
expect![[r#"
- crate
- f: v
- "#]],
+ crate
+ - f : value
+ "#]],
);
}
@@ -883,7 +914,8 @@ extern {
"#,
expect![[r#"
crate
- S: v
+ - S : value
+ - (legacy) m : macro!
"#]],
);
}
@@ -909,8 +941,8 @@ fn derive() {}
"#,
expect![[r#"
crate
- S: t v
- derive: m
+ - S : type value
+ - derive : macro#
"#]],
);
}
@@ -932,7 +964,7 @@ enum E {
"#,
expect![[r#"
crate
- E: t
+ - E : type
"#]],
);
}
@@ -947,7 +979,7 @@ struct S;
"#,
expect![[r#"
crate
- S: t v
+ - S : type value
"#]],
);
}
@@ -975,6 +1007,8 @@ b! { static = #[] ();}
"#,
expect![[r#"
crate
+ - (legacy) a : macro!
+ - (legacy) b : macro!
"#]],
);
}
@@ -995,7 +1029,9 @@ indirect_macro!();
"#,
expect![[r#"
crate
- S: t
+ - S : type
+ - (legacy) indirect_macro : macro!
+ - (legacy) item : macro!
"#]],
);
}
@@ -1029,13 +1065,13 @@ pub fn derive_macro_2(_item: TokenStream) -> TokenStream {
"#,
expect![[r#"
crate
- AnotherTrait: m
- DummyTrait: m
- TokenStream: t v
- attribute_macro: v m
- derive_macro: v
- derive_macro_2: v
- function_like_macro: v m
+ - AnotherTrait : macro#
+ - DummyTrait : macro#
+ - TokenStream : type value
+ - attribute_macro : value macro#
+ - derive_macro : value
+ - derive_macro_2 : value
+ - function_like_macro : value macro!
"#]],
);
}
@@ -1075,9 +1111,9 @@ macro_rules! mbe {
"#,
expect![[r#"
crate
- DummyTrait: mg
- attribute_macro: mg
- function_like_macro: mg
+ - DummyTrait : macro# (glob)
+ - attribute_macro : macro# (glob)
+ - function_like_macro : macro! (glob)
"#]],
);
}
@@ -1119,8 +1155,8 @@ structs!(Foo);
"#,
expect![[r#"
crate
- Foo: t
- structs: m
+ - Foo : type
+ - structs : macro!
"#]],
);
}
@@ -1143,7 +1179,7 @@ pub mod prelude {
"#,
expect![[r#"
crate
- S: t v
+ - S : type value
"#]],
)
}
@@ -1161,6 +1197,7 @@ m!(
"#,
expect![[r#"
crate
+ - (legacy) m : macro!
"#]],
)
}
@@ -1193,12 +1230,15 @@ struct A;
struct B;
"#,
expect![[r#"
- crate
- A: t v
- B: t v
- inner_a: m
- inner_b: m
- "#]],
+ crate
+ - A : type value
+ - B : type value
+ - inner_a : macro!
+ - inner_b : macro!
+ - (legacy) include : macro!
+ - (legacy) inner_a : macro!
+ - (legacy) inner_b : macro!
+ "#]],
);
}
@@ -1227,8 +1267,11 @@ struct A;
"#,
expect![[r#"
crate
- A: t v
- inner: m
+ - A : type value
+ - inner : macro!
+ - (legacy) include : macro!
+ - (legacy) inner : macro!
+ - (legacy) m : macro!
"#]],
);
// eager -> MBE -> $crate::mbe
@@ -1256,8 +1299,11 @@ struct A;
"#,
expect![[r#"
crate
- A: t v
- inner: m
+ - A : type value
+ - inner : macro!
+ - (legacy) include : macro!
+ - (legacy) inner : macro!
+ - (legacy) n : macro!
"#]],
);
}
@@ -1292,20 +1338,20 @@ pub mod ip_address {
"#,
expect![[r#"
crate
- company_name: t
+ - company_name : type
crate::company_name
- network: t
+ - network : type
crate::company_name::network
- v1: t
+ - v1 : type
crate::company_name::network::v1
- IpAddress: t
- ip_address: t
+ - IpAddress : type
+ - ip_address : type
crate::company_name::network::v1::ip_address
- IpType: t
+ - IpType : type
"#]],
);
}
@@ -1338,20 +1384,20 @@ pub mod ip_address {
"#,
expect![[r#"
crate
- company_name: t
+ - company_name : type
crate::company_name
- network: t
+ - network : type
crate::company_name::network
- v1: t
+ - v1 : type
crate::company_name::network::v1
- IpAddress: t
- ip_address: t
+ - IpAddress : type
+ - ip_address : type
crate::company_name::network::v1::ip_address
- IpType: t
+ - IpType : type
"#]],
);
}
@@ -1392,30 +1438,38 @@ pub struct Url {}
"#,
expect![[r#"
crate
- nested: t
+ - nested : type
+ - (legacy) include : macro!
crate::nested
- company_name: t
- different_company: t
- util: t
+ - company_name : type
+ - different_company : type
+ - util : type
+ - (legacy) include : macro!
crate::nested::company_name
- network: t
+ - network : type
+ - (legacy) include : macro!
crate::nested::company_name::network
- v1: t
+ - v1 : type
+ - (legacy) include : macro!
crate::nested::company_name::network::v1
- IpAddress: t
+ - IpAddress : type
+ - (legacy) include : macro!
crate::nested::different_company
- network: t
+ - network : type
+ - (legacy) include : macro!
crate::nested::different_company::network
- Url: t
+ - Url : type
+ - (legacy) include : macro!
crate::nested::util
- Helper: t
+ - Helper : type
+ - (legacy) include : macro!
"#]],
);
}
@@ -1448,7 +1502,7 @@ fn proc_attr(a: TokenStream, b: TokenStream) -> TokenStream { a }
let krate = *db.all_crates().last().expect("no crate graph present");
let def_map = crate_def_map(&db, krate);
- let root_module = &def_map[DefMap::ROOT].scope;
+ let root_module = &def_map[def_map.root].scope;
assert!(
root_module.legacy_macros().count() == 0,
"`#[macro_use]` shouldn't bring macros into textual macro scope",
@@ -1500,11 +1554,11 @@ pub mod prelude {
"#,
expect![[r#"
crate
- Ok: t v
- bar: m
- dep: te
- foo: m
- ok: v
+ - Ok : type value
+ - bar : macro!
+ - dep : type (extern)
+ - foo : macro!
+ - ok : value
"#]],
);
}
@@ -1533,11 +1587,13 @@ macro_rules! mk_foo {
"#,
expect![[r#"
crate
- a: t
- lib: te
+ - a : type
+ - lib : type (extern)
+ - (legacy) foo : macro!
crate::a
- Ok: t v
+ - Ok : type value
+ - (legacy) foo : macro!
"#]],
);
}
@@ -1553,7 +1609,7 @@ macro_rules! derive { () => {} }
#[derive(Clone)]
struct S;
"#,
- |map| assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1),
+ |map| assert_eq!(map.modules[map.root].scope.builtin_derive_impls().len(), 1),
);
}
@@ -1588,10 +1644,139 @@ pub mod prelude {
"#,
expect![[r#"
crate
- Ok: t v
- bar: mi
- foo: mi
- ok: v
+ - Ok : type value
+ - bar : macro# (import)
+ - foo : macro# (import)
+ - ok : value
+ "#]],
+ );
+}
+
+#[test]
+fn macro_rules_mixed_style() {
+ check(
+ r#"
+
+macro_rules! foo {
+ () => {};
+ attr() () => {};
+ derive() () => {};
+}
+
+use foo;
+"#,
+ expect![[r#"
+ crate
+ - foo : macro!# (import)
+ - (legacy) foo : macro!#
+"#]],
+ );
+}
+
+#[test]
+fn macro_2_mixed_style() {
+ check(
+ r#"
+
+macro foo {
+ () => {};
+ attr() () => {};
+ derive() () => {};
+}
+
+use foo;
+"#,
+ expect![[r#"
+ crate
+ - foo : macro!#
+ "#]],
+ );
+}
+
+#[test]
+fn macro_rules_attr() {
+ check(
+ r#"
+
+macro_rules! my_attr {
+ attr() ($($tt:tt)*) => { fn attr_fn() {} }
+}
+
+#[my_attr]
+enum MyEnum {}
+
+"#,
+ expect![[r#"
+ crate
+ - attr_fn : value
+ - (legacy) my_attr : macro#
+"#]],
+ );
+}
+
+#[test]
+fn macro_2_attr() {
+ check(
+ r#"
+
+macro my_attr {
+ attr() ($($tt:tt)*) => { fn attr_fn() {} }
+}
+
+#[my_attr]
+enum MyEnum {}
+
+"#,
+ expect![[r#"
+ crate
+ - attr_fn : value
+ - my_attr : macro#
+"#]],
+ );
+}
+
+#[test]
+fn macro_rules_derive() {
+ check(
+ r#"
+//- minicore: derive
+
+macro_rules! MyDerive {
+ derive() ($($tt:tt)*) => { fn derived_fn() {} }
+}
+
+#[derive(MyDerive)]
+enum MyEnum {}
+
+"#,
+ expect![[r#"
+ crate
+ - MyEnum : type
+ - derived_fn : value
+ - (legacy) MyDerive : macro#
+ "#]],
+ );
+}
+
+#[test]
+fn macro_2_derive() {
+ check(
+ r#"
+//- minicore: derive
+
+macro MyDerive {
+ derive() ($($tt:tt)*) => { fn derived_fn() {} }
+}
+
+#[derive(MyDerive)]
+enum MyEnum {}
+
+"#,
+ expect![[r#"
+ crate
+ - MyDerive : macro#
+ - MyEnum : type
+ - derived_fn : value
"#]],
);
}