]> git.lizzy.rs Git - rust.git/blob - src/test/ui/hygiene/generic_params.rs
Merge commit '9809f5d21990d9e24b3e9876ea7da756fd4e9def' into libgccjit-codegen
[rust.git] / src / test / ui / hygiene / generic_params.rs
1 // Ensure that generic parameters always have modern hygiene.
2
3 // check-pass
4 // ignore-pretty pretty-printing is unhygienic
5
6 #![feature(decl_macro, rustc_attrs, const_generics)]
7 //~^ WARNING the feature `const_generics` is incomplete
8
9 mod type_params {
10     macro m($T:ident) {
11         fn f<$T: Clone, T: PartialEq>(t1: $T, t2: T) -> ($T, bool) {
12             (t1.clone(), t2 == t2)
13         }
14     }
15
16     #[rustc_macro_transparency = "semitransparent"]
17     macro n($T:ident) {
18         fn g<$T: Clone>(t1: $T, t2: T) -> (T, $T) {
19             (t1.clone(), t2.clone())
20         }
21         fn h<T: Clone>(t1: $T, t2: T) -> (T, $T) {
22             (t1.clone(), t2.clone())
23         }
24     }
25
26     #[rustc_macro_transparency = "transparent"]
27     macro p($T:ident) {
28         fn j<$T: Clone>(t1: $T, t2: T) -> (T, $T) {
29             (t1.clone(), t2.clone())
30         }
31         fn k<T: Clone>(t1: $T, t2: T) -> (T, $T) {
32             (t1.clone(), t2.clone())
33         }
34     }
35
36     m!(T);
37     n!(T);
38     p!(T);
39 }
40
41 mod lifetime_params {
42     macro m($a:lifetime) {
43         fn f<'b, 'c, $a: 'b, 'a: 'c>(t1: &$a(), t2: &'a ()) -> (&'b (), &'c ()) {
44             (t1, t2)
45         }
46     }
47
48     #[rustc_macro_transparency = "semitransparent"]
49     macro n($a:lifetime) {
50         fn g<$a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
51             (t1, t2)
52         }
53         fn h<'a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
54             (t1, t2)
55         }
56     }
57
58     #[rustc_macro_transparency = "transparent"]
59     macro p($a:lifetime) {
60         fn j<$a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
61             (t1, t2)
62         }
63         fn k<'a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
64             (t1, t2)
65         }
66     }
67
68     m!('a);
69     n!('a);
70     p!('a);
71 }
72
73 mod const_params {
74     macro m($C:ident) {
75         fn f<const $C: usize, const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); $C], [(); C]) {
76             (t1, t2)
77         }
78     }
79
80     #[rustc_macro_transparency = "semitransparent"]
81     macro n($C:ident) {
82         fn g<const $C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
83             (t1, t2)
84         }
85         fn h<const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
86             (t1, t2)
87         }
88     }
89
90     #[rustc_macro_transparency = "transparent"]
91     macro p($C:ident) {
92         fn j<const $C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
93             (t1, t2)
94         }
95         fn k<const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
96             (t1, t2)
97         }
98     }
99
100     m!(C);
101     n!(C);
102     p!(C);
103 }
104
105 fn main() {}