]> git.lizzy.rs Git - rust.git/blob - crates/hir_def/src/macro_expansion_tests/proc_macros.rs
feat: Make unqualified derive attributes flyimportable
[rust.git] / crates / hir_def / src / macro_expansion_tests / proc_macros.rs
1 //! Tests for user-defined procedural macros.
2 //!
3 //! Note `//- proc_macros: identity` fixture metas in tests -- we don't use real
4 //! proc-macros here, as that would be slow. Instead, we use several hard-coded
5 //! in-memory macros.
6 use expect_test::expect;
7
8 use crate::macro_expansion_tests::check;
9
10 #[test]
11 fn attribute_macro_attr_censoring() {
12     cov_mark::check!(attribute_macro_attr_censoring);
13     check(
14         r#"
15 //- proc_macros: identity
16 #[attr1] #[proc_macros::identity] #[attr2]
17 struct S;
18 "#,
19         expect![[r##"
20 #[attr1] #[proc_macros::identity] #[attr2]
21 struct S;
22
23 #[attr1]
24 #[attr2] struct S;"##]],
25     );
26 }
27
28 #[test]
29 fn derive_censoring() {
30     cov_mark::check!(derive_censoring);
31     check(
32         r#"
33 //- proc_macros: derive_identity
34 #[attr1]
35 #[derive(Foo)]
36 #[derive(proc_macros::DeriveIdentity)]
37 #[derive(Bar)]
38 #[attr2]
39 struct S;
40 "#,
41         expect![[r##"
42 #[attr1]
43 #[derive(Foo)]
44 #[derive(proc_macros::DeriveIdentity)]
45 #[derive(Bar)]
46 #[attr2]
47 struct S;
48
49 #[attr1]
50 #[derive(Bar)]
51 #[attr2] struct S;"##]],
52     );
53 }