]> git.lizzy.rs Git - rust.git/blob - tests/ui/single-use-lifetime/issue-104440.rs
Rollup merge of #104012 - chenyukang:yukang/fix-103882-deli-indentation, r=petrochenkov
[rust.git] / tests / ui / single-use-lifetime / issue-104440.rs
1 #![feature(decl_macro, rustc_attrs)]
2 #![deny(single_use_lifetimes)]
3
4 mod type_params {
5     macro m($T:ident) {
6         fn f<$T: Clone, T: PartialEq>(t1: $T, t2: T) -> ($T, bool) {
7             (t1.clone(), t2 == t2)
8         }
9     }
10
11     #[rustc_macro_transparency = "semitransparent"]
12     macro n($T:ident) {
13         fn g<$T: Clone>(t1: $T, t2: T) -> (T, $T) {
14             (t1.clone(), t2.clone())
15         }
16         fn h<T: Clone>(t1: $T, t2: T) -> (T, $T) {
17             (t1.clone(), t2.clone())
18         }
19     }
20
21     #[rustc_macro_transparency = "transparent"]
22     macro p($T:ident) {
23         fn j<$T: Clone>(t1: $T, t2: T) -> (T, $T) {
24             (t1.clone(), t2.clone())
25         }
26         fn k<T: Clone>(t1: $T, t2: T) -> (T, $T) {
27             (t1.clone(), t2.clone())
28         }
29     }
30
31     m!(T);
32     n!(T);
33     p!(T);
34 }
35
36 mod lifetime_params {
37     macro m($a:lifetime) {
38         fn f<'b, 'c, $a: 'b, 'a: 'c>(t1: &$a(), t2: &'a ()) -> (&'b (), &'c ()) { //~ ERROR lifetime parameter `'a` only used once
39             (t1, t2)
40         }
41     }
42
43     #[rustc_macro_transparency = "semitransparent"]
44     macro n($a:lifetime) {
45         fn g<$a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
46             (t1, t2)
47         }
48         fn h<'a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
49             (t1, t2)
50         }
51     }
52
53     #[rustc_macro_transparency = "transparent"]
54     macro p($a:lifetime) {
55         fn j<$a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
56             (t1, t2)
57         }
58         fn k<'a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) {
59             (t1, t2)
60         }
61     }
62
63     m!('a); //~ ERROR lifetime parameter `'a` only used once
64     n!('a);
65     p!('a);
66 }
67
68 mod const_params {
69     macro m($C:ident) {
70         fn f<const $C: usize, const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); $C], [(); C]) {
71             (t1, t2)
72         }
73     }
74
75     #[rustc_macro_transparency = "semitransparent"]
76     macro n($C:ident) {
77         fn g<const $C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
78             (t1, t2)
79         }
80         fn h<const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
81             (t1, t2)
82         }
83     }
84
85     #[rustc_macro_transparency = "transparent"]
86     macro p($C:ident) {
87         fn j<const $C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
88             (t1, t2)
89         }
90         fn k<const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) {
91             (t1, t2)
92         }
93     }
94
95     m!(C);
96     n!(C);
97     p!(C);
98 }
99
100 fn main() {}