]> git.lizzy.rs Git - rust.git/blob - crates/hir_def/src/macro_expansion_tests/builtin_derive_macro.rs
Merge #10434
[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 Copy {}
30 #[derive(Copy)]
31 struct Foo;
32 "#,
33         expect![[r##"
34 #[rustc_builtin_macro]
35 macro Copy {}
36 #[derive(Copy)]
37 struct Foo;
38
39 impl < > crate ::marker::Copy for Foo< > {}"##]],
40     );
41 }
42
43 #[test]
44 fn test_copy_expand_with_type_params() {
45     check(
46         r#"
47 //- minicore: derive, copy
48 #[derive(Copy)]
49 struct Foo<A, B>;
50 "#,
51         expect![[r##"
52 #[derive(Copy)]
53 struct Foo<A, B>;
54
55 impl <T0: core::marker::Copy, T1: core::marker::Copy> core::marker::Copy for Foo<T0, T1> {}"##]],
56     );
57 }
58
59 #[test]
60 fn test_copy_expand_with_lifetimes() {
61     // We currently just ignore lifetimes
62     check(
63         r#"
64 //- minicore: derive, copy
65 #[derive(Copy)]
66 struct Foo<A, B, 'a, 'b>;
67 "#,
68         expect![[r##"
69 #[derive(Copy)]
70 struct Foo<A, B, 'a, 'b>;
71
72 impl <T0: core::marker::Copy, T1: core::marker::Copy> core::marker::Copy for Foo<T0, T1> {}"##]],
73     );
74 }
75
76 #[test]
77 fn test_clone_expand() {
78     check(
79         r#"
80 //- minicore: derive, clone
81 #[derive(Clone)]
82 struct Foo<A, B>;
83 "#,
84         expect![[r##"
85 #[derive(Clone)]
86 struct Foo<A, B>;
87
88 impl <T0: core::clone::Clone, T1: core::clone::Clone> core::clone::Clone for Foo<T0, T1> {}"##]],
89     );
90 }