]> git.lizzy.rs Git - rust.git/blob - crates/hir_def/src/macro_expansion_tests/builtin_derive_macro.rs
Merge #10789
[rust.git] / crates / hir_def / src / macro_expansion_tests / builtin_derive_macro.rs
1 //! Tests for `builtin_derive_macro.rs` from `hir_expand`.
2
3 use expect_test::expect;
4
5 use crate::macro_expansion_tests::check;
6
7 #[test]
8 fn test_copy_expand_simple() {
9     check(
10         r#"
11 //- minicore: derive, copy
12 #[derive(Copy)]
13 struct Foo;
14 "#,
15         expect![[r##"
16 #[derive(Copy)]
17 struct Foo;
18
19 impl < > core::marker::Copy for Foo< > {}"##]],
20     );
21 }
22
23 #[test]
24 fn test_copy_expand_in_core() {
25     cov_mark::check!(test_copy_expand_in_core);
26     check(
27         r#"
28 #[rustc_builtin_macro]
29 macro derive {}
30 #[rustc_builtin_macro]
31 macro Copy {}
32 #[derive(Copy)]
33 struct Foo;
34 "#,
35         expect![[r##"
36 #[rustc_builtin_macro]
37 macro derive {}
38 #[rustc_builtin_macro]
39 macro Copy {}
40 #[derive(Copy)]
41 struct Foo;
42
43 impl < > crate ::marker::Copy for Foo< > {}"##]],
44     );
45 }
46
47 #[test]
48 fn test_copy_expand_with_type_params() {
49     check(
50         r#"
51 //- minicore: derive, copy
52 #[derive(Copy)]
53 struct Foo<A, B>;
54 "#,
55         expect![[r##"
56 #[derive(Copy)]
57 struct Foo<A, B>;
58
59 impl <T0: core::marker::Copy, T1: core::marker::Copy> core::marker::Copy for Foo<T0, T1> {}"##]],
60     );
61 }
62
63 #[test]
64 fn test_copy_expand_with_lifetimes() {
65     // We currently just ignore lifetimes
66     check(
67         r#"
68 //- minicore: derive, copy
69 #[derive(Copy)]
70 struct Foo<A, B, 'a, 'b>;
71 "#,
72         expect![[r##"
73 #[derive(Copy)]
74 struct Foo<A, B, 'a, 'b>;
75
76 impl <T0: core::marker::Copy, T1: core::marker::Copy> core::marker::Copy for Foo<T0, T1> {}"##]],
77     );
78 }
79
80 #[test]
81 fn test_clone_expand() {
82     check(
83         r#"
84 //- minicore: derive, clone
85 #[derive(Clone)]
86 struct Foo<A, B>;
87 "#,
88         expect![[r##"
89 #[derive(Clone)]
90 struct Foo<A, B>;
91
92 impl <T0: core::clone::Clone, T1: core::clone::Clone> core::clone::Clone for Foo<T0, T1> {}"##]],
93     );
94 }