]> git.lizzy.rs Git - rust.git/blob - src/test/ui/hygiene/generic_params.rs
Rollup merge of #90202 - matthewjasper:xcrate-hygiene, r=petrochenkov
[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)]
7
8 mod type_params {
9     macro m($T:ident) {
10         fn f<$T: Clone, T: PartialEq>(t1: $T, t2: T) -> ($T, bool) {
11             (t1.clone(), t2 == t2)
12         }
13     }
14
15     #[rustc_macro_transparency = "semitransparent"]
16     macro n($T:ident) {
17         fn g<$T: Clone>(t1: $T, t2: T) -> (T, $T) {
18             (t1.clone(), t2.clone())
19         }
20         fn h<T: Clone>(t1: $T, t2: T) -> (T, $T) {
21             (t1.clone(), t2.clone())
22         }
23     }
24
25     #[rustc_macro_transparency = "transparent"]
26     macro p($T:ident) {
27         fn j<$T: Clone>(t1: $T, t2: T) -> (T, $T) {
28             (t1.clone(), t2.clone())
29         }
30         fn k<T: Clone>(t1: $T, t2: T) -> (T, $T) {
31             (t1.clone(), t2.clone())
32         }
33     }
34
35     m!(T);
36     n!(T);
37     p!(T);
38 }
39
40 mod lifetime_params {
41     macro m($a:lifetime) {
42         fn f<'b, 'c, $a: 'b, 'a: 'c>(t1: &$a(), t2: &'a ()) -> (&'b (), &'c ()) {
43             (t1, t2)
44         }
45     }
46
47     #[rustc_macro_transparency = "semitransparent"]
48     macro n($a:lifetime) {
49         fn g<$a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
50             (t1, t2)
51         }
52         fn h<'a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
53             (t1, t2)
54         }
55     }
56
57     #[rustc_macro_transparency = "transparent"]
58     macro p($a:lifetime) {
59         fn j<$a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
60             (t1, t2)
61         }
62         fn k<'a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
63             (t1, t2)
64         }
65     }
66
67     m!('a);
68     n!('a);
69     p!('a);
70 }
71
72 mod const_params {
73     macro m($C:ident) {
74         fn f<const $C: usize, const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); $C], [(); C]) {
75             (t1, t2)
76         }
77     }
78
79     #[rustc_macro_transparency = "semitransparent"]
80     macro n($C:ident) {
81         fn g<const $C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
82             (t1, t2)
83         }
84         fn h<const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
85             (t1, t2)
86         }
87     }
88
89     #[rustc_macro_transparency = "transparent"]
90     macro p($C:ident) {
91         fn j<const $C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
92             (t1, t2)
93         }
94         fn k<const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
95             (t1, t2)
96         }
97     }
98
99     m!(C);
100     n!(C);
101     p!(C);
102 }
103
104 fn main() {}