Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/macro_expansion_tests/proc_macros.rs')
| -rw-r--r-- | crates/hir-def/src/macro_expansion_tests/proc_macros.rs | 121 |
1 files changed, 114 insertions, 7 deletions
diff --git a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs index 6952a9da10..5216246910 100644 --- a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs +++ b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs @@ -9,37 +9,93 @@ use crate::macro_expansion_tests::{check, check_errors}; #[test] fn attribute_macro_attr_censoring() { - cov_mark::check!(attribute_macro_attr_censoring); check( r#" //- proc_macros: identity -#[attr1] #[proc_macros::identity] #[attr2] +//- minicore: derive +#[attr1] #[derive()] #[proc_macros::identity] #[attr2] struct S; + +/// Foo +#[cfg_attr(false, doc = "abc...", attr1)] +mod foo { + #![cfg_attr(true, cfg_attr(true, foo, cfg_attr(false, bar), proc_macros::identity))] + #![cfg_attr(true, doc = "123...", attr2)] + #![attr3] + + #[cfg_attr(true, cfg(false))] + fn foo() {} + + #[cfg(true)] + fn bar() {} +} "#, - expect![[r#" -#[attr1] #[proc_macros::identity] #[attr2] + expect![[r##" +#[attr1] #[derive()] #[proc_macros::identity] #[attr2] struct S; +/// Foo +#[cfg_attr(false, doc = "abc...", attr1)] +mod foo { + #![cfg_attr(true, cfg_attr(true, foo, cfg_attr(false, bar), proc_macros::identity))] + #![cfg_attr(true, doc = "123...", attr2)] + #![attr3] + + #[cfg_attr(true, cfg(false))] + fn foo() {} + + #[cfg(true)] + fn bar() {} +} + #[attr1] -#[attr2] struct S;"#]], +#[attr2] struct S; +#[doc = " Foo"] mod foo { + # ![foo] + # ![doc = "123..."] + # ![attr2] + # ![attr3] + #[cfg_attr(true , cfg(false ))] fn foo() {} + #[cfg(true )] fn bar() {} +}"##]], ); } #[test] fn derive_censoring() { - cov_mark::check!(derive_censoring); check( r#" //- proc_macros: derive_identity //- minicore:derive +use derive as my_cool_derive; #[attr1] #[derive(Foo)] #[derive(proc_macros::DeriveIdentity)] #[derive(Bar)] #[attr2] struct S; + +#[my_cool_derive()] +#[cfg_attr(true, derive(), attr1, derive(proc_macros::DeriveIdentity))] +#[my_cool_derive()] +struct Foo { + #[cfg_attr(false, cfg(false), attr2)] + v1: i32, + #[cfg_attr(true, cfg(false), attr2)] + v1: i32, + #[cfg_attr(true, attr3)] + v2: fn(#[cfg(false)] param: i32, #[cfg_attr(true, attr4)] param2: u32), + v3: Foo<{ + #[cfg(false)] + let foo = 123; + 456 + }>, + #[cfg(false)] + v4: bool // No comma here +} "#, expect![[r#" +use derive as my_cool_derive; #[attr1] #[derive(Foo)] #[derive(proc_macros::DeriveIdentity)] @@ -47,6 +103,32 @@ struct S; #[attr2] struct S; +#[my_cool_derive()] +#[cfg_attr(true, derive(), attr1, derive(proc_macros::DeriveIdentity))] +#[my_cool_derive()] +struct Foo { + #[cfg_attr(false, cfg(false), attr2)] + v1: i32, + #[cfg_attr(true, cfg(false), attr2)] + v1: i32, + #[cfg_attr(true, attr3)] + v2: fn(#[cfg(false)] param: i32, #[cfg_attr(true, attr4)] param2: u32), + v3: Foo<{ + #[cfg(false)] + let foo = 123; + 456 + }>, + #[cfg(false)] + v4: bool // No comma here +} + +#[attr1] +#[my_cool_derive()] struct Foo { + v1: i32, #[attr3]v2: fn(#[attr4]param2: u32), v3: Foo< { + 456 + } + >, +} #[attr1] #[derive(Bar)] #[attr2] struct S;"#]], @@ -87,7 +169,7 @@ fn foo() { bar.; blub } fn foo() { bar.; blub } fn foo() { - bar. ; + bar.; blub }"#]], ); @@ -234,3 +316,28 @@ use proc_macros::disallow_cfg; expect![[r#""#]], ); } + +#[test] +fn derive_helpers_are_ignored() { + check( + r#" +//- proc_macros: identity, helper_should_be_ignored, helper_should_be_ignored_derive +//- minicore: derive +use proc_macros::{identity, helper_should_be_ignored, HelperShouldBeIgnoredDerive}; + +#[derive(HelperShouldBeIgnoredDerive)] +#[helper_should_be_ignored] +#[identity] +struct Foo; +"#, + expect![[r#" +use proc_macros::{identity, helper_should_be_ignored, HelperShouldBeIgnoredDerive}; + +#[derive(HelperShouldBeIgnoredDerive)] +#[helper_should_be_ignored] +#[identity] +struct Foo; + +#[helper_should_be_ignored] struct Foo;"#]], + ); +} |