From cf3b4f1e208247c9d171273dabff9c6b3c98a240 Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 10 Apr 2021 17:49:12 +0200 Subject: hir_ty: Expand macros at type position --- crates/hir_ty/src/tests/macros.rs | 169 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index b8e373ed8..cbe05a5c1 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs @@ -1074,3 +1074,172 @@ fn macro_in_arm() { "#]], ); } + +#[test] +fn macro_in_type_alias_position() { + check_infer( + r#" + macro_rules! U32 { + () => { u32 }; + } + + trait Foo { + type Ty; + } + + impl Foo for T { + type Ty = U32!(); + } + + type TayTo = U32!(); + + fn testy() { + let a: <() as Foo>::Ty; + let b: TayTo; + } + "#, + expect![[r#" + 147..196 '{ ...yTo; }': () + 157..158 'a': u32 + 185..186 'b': u32 + "#]], + ); +} + +#[test] +fn nested_macro_in_type_alias_position() { + check_infer( + r#" + macro_rules! U32Inner2 { + () => { u32 }; + } + + macro_rules! U32Inner1 { + () => { U32Inner2!() }; + } + + macro_rules! U32 { + () => { U32Inner1!() }; + } + + trait Foo { + type Ty; + } + + impl Foo for T { + type Ty = U32!(); + } + + type TayTo = U32!(); + + fn testy() { + let a: <() as Foo>::Ty; + let b: TayTo; + } + "#, + expect![[r#" + 259..308 '{ ...yTo; }': () + 269..270 'a': u32 + 297..298 'b': u32 + "#]], + ); +} + +#[test] +fn macros_in_type_alias_position_generics() { + check_infer( + r#" + struct Foo(A, B); + + macro_rules! U32 { + () => { u32 }; + } + + macro_rules! Bar { + () => { Foo }; + } + + trait Moo { + type Ty; + } + + impl Moo for T { + type Ty = Bar!(); + } + + type TayTo = Bar!(); + + fn main() { + let a: <() as Moo>::Ty; + let b: TayTo; + } + "#, + expect![[r#" + 228..277 '{ ...yTo; }': () + 238..239 'a': Foo + 266..267 'b': Foo + "#]], + ); +} + +#[test] +fn macros_in_type_position() { + check_infer( + r#" + struct Foo(A, B); + + macro_rules! U32 { + () => { u32 }; + } + + macro_rules! Bar { + () => { Foo }; + } + + fn main() { + let a: Bar!(); + } + "#, + expect![[r#" + 133..155 '{ ...!(); }': () + 143..144 'a': Foo + "#]], + ); +} + +#[test] +fn macros_in_type_generics() { + check_infer( + r#" + struct Foo(A, B); + + macro_rules! U32 { + () => { u32 }; + } + + macro_rules! Bar { + () => { Foo }; + } + + trait Moo { + type Ty; + } + + impl Moo for T { + type Ty = Foo; + } + + type TayTo = Foo; + + fn main() { + let a: <() as Moo>::Ty; + let b: TayTo; + } + "#, + expect![[r#" + 254..303 '{ ...yTo; }': () + 264..265 'a': Foo, Foo> + 292..293 'b': Foo, u32> + "#]], + ); +} -- cgit v1.2.3