]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2565-param-attrs/param-attrs-allowed.rs
Rollup merge of #61990 - llogiq:questionmark-test, r=QuietMisdreavus
[rust.git] / src / test / ui / rfc-2565-param-attrs / param-attrs-allowed.rs
1 // compile-flags: --cfg something
2 // build-pass (FIXME(62277): could be check-pass?)
3
4 #![feature(param_attrs)]
5
6 extern "C" {
7     fn ffi(
8         #[allow(C)] a: i32,
9         #[cfg(something)] b: i32,
10         #[cfg_attr(something, cfg(nothing))] c: i32,
11         #[deny(C)] d: i32,
12         #[forbid(C)] #[warn(C)] ...
13     );
14 }
15
16 type FnType = fn(
17     #[allow(C)] a: i32,
18     #[cfg(something)] b: i32,
19     #[cfg_attr(something, cfg(nothing))] c: i32,
20     #[deny(C)] d: i32,
21     #[forbid(C)] #[warn(C)] e: i32
22 );
23
24 pub fn foo(
25     #[allow(C)] a: i32,
26     #[cfg(something)] b: i32,
27     #[cfg_attr(something, cfg(nothing))] c: i32,
28     #[deny(C)] d: i32,
29     #[forbid(C)] #[warn(C)] e: i32
30 ) {}
31
32 // self, &self and &mut self
33
34 struct SelfStruct {}
35 impl SelfStruct {
36     fn foo(
37         #[allow(C)] self,
38         #[cfg(something)] a: i32,
39         #[cfg_attr(something, cfg(nothing))]
40         #[deny(C)] b: i32,
41     ) {}
42 }
43
44 struct RefStruct {}
45 impl RefStruct {
46     fn foo(
47         #[allow(C)] &self,
48         #[cfg(something)] a: i32,
49         #[cfg_attr(something, cfg(nothing))]
50         #[deny(C)] b: i32,
51     ) {}
52 }
53 trait RefTrait {
54     fn foo(
55         #[forbid(C)] &self,
56         #[warn(C)] a: i32
57     ) {}
58 }
59 impl RefTrait for RefStruct {
60     fn foo(
61         #[forbid(C)] &self,
62         #[warn(C)] a: i32
63     ) {}
64 }
65
66 struct MutStruct {}
67 impl MutStruct {
68     fn foo(
69         #[allow(C)] &mut self,
70         #[cfg(something)] a: i32,
71         #[cfg_attr(something, cfg(nothing))]
72         #[deny(C)] b: i32,
73     ) {}
74 }
75 trait MutTrait {
76     fn foo(
77         #[forbid(C)] &mut self,
78         #[warn(C)] a: i32
79     ) {}
80 }
81 impl MutTrait for MutStruct {
82     fn foo(
83         #[forbid(C)] &mut self,
84         #[warn(C)] a: i32
85     ) {}
86 }
87
88 // self: Self, self: &Self and self: &mut Self
89
90 struct NamedSelfSelfStruct {}
91 impl NamedSelfSelfStruct {
92     fn foo(
93         #[allow(C)] self: Self,
94         #[cfg(something)] a: i32,
95         #[cfg_attr(something, cfg(nothing))]
96         #[deny(C)] b: i32,
97     ) {}
98 }
99
100 struct NamedSelfRefStruct {}
101 impl NamedSelfRefStruct {
102     fn foo(
103         #[allow(C)] self: &Self,
104         #[cfg(something)] a: i32,
105         #[cfg_attr(something, cfg(nothing))]
106         #[deny(C)] b: i32,
107     ) {}
108 }
109 trait NamedSelfRefTrait {
110     fn foo(
111         #[forbid(C)] self: &Self,
112         #[warn(C)] a: i32
113     ) {}
114 }
115 impl NamedSelfRefTrait for NamedSelfRefStruct {
116     fn foo(
117         #[forbid(C)] self: &Self,
118         #[warn(C)] a: i32
119     ) {}
120 }
121
122 struct NamedSelfMutStruct {}
123 impl NamedSelfMutStruct {
124     fn foo(
125         #[allow(C)] self: &mut Self,
126         #[cfg(something)] a: i32,
127         #[cfg_attr(something, cfg(nothing))]
128         #[deny(C)] b: i32,
129     ) {}
130 }
131 trait NamedSelfMutTrait {
132     fn foo(
133         #[forbid(C)] self: &mut Self,
134         #[warn(C)] a: i32
135     ) {}
136 }
137 impl NamedSelfMutTrait for NamedSelfMutStruct {
138     fn foo(
139         #[forbid(C)] self: &mut Self,
140         #[warn(C)] a: i32
141     ) {}
142 }
143
144 // &'a self and &'a mut self
145
146 struct NamedLifetimeRefStruct {}
147 impl NamedLifetimeRefStruct {
148     fn foo<'a>(
149         #[allow(C)] self: &'a Self,
150         #[cfg(something)] a: i32,
151         #[cfg_attr(something, cfg(nothing))]
152         #[deny(C)] b: i32,
153     ) {}
154 }
155 trait NamedLifetimeRefTrait {
156     fn foo<'a>(
157         #[forbid(C)] &'a self,
158         #[warn(C)] a: i32
159     ) {}
160 }
161 impl NamedLifetimeRefTrait for NamedLifetimeRefStruct {
162     fn foo<'a>(
163         #[forbid(C)] &'a self,
164         #[warn(C)] a: i32
165     ) {}
166 }
167
168 struct NamedLifetimeMutStruct {}
169 impl NamedLifetimeMutStruct {
170     fn foo<'a>(
171         #[allow(C)] self: &'a mut Self,
172         #[cfg(something)] a: i32,
173         #[cfg_attr(something, cfg(nothing))]
174         #[deny(C)] b: i32,
175     ) {}
176 }
177 trait NamedLifetimeMutTrait {
178     fn foo<'a>(
179         #[forbid(C)] &'a mut self,
180         #[warn(C)] a: i32
181     ) {}
182 }
183 impl NamedLifetimeMutTrait for NamedLifetimeMutStruct {
184     fn foo<'a>(
185         #[forbid(C)] &'a mut self,
186         #[warn(C)] a: i32
187     ) {}
188 }
189
190 // Box<Self>
191
192 struct BoxSelfStruct {}
193 impl BoxSelfStruct {
194     fn foo(
195         #[allow(C)] self: Box<Self>,
196         #[cfg(something)] a: i32,
197         #[cfg_attr(something, cfg(nothing))]
198         #[deny(C)] b: i32,
199     ) {}
200 }
201 trait BoxSelfTrait {
202     fn foo(
203         #[forbid(C)] self: Box<Self>,
204         #[warn(C)] a: i32
205     ) {}
206 }
207 impl BoxSelfTrait for BoxSelfStruct {
208     fn foo(
209         #[forbid(C)] self: Box<Self>,
210         #[warn(C)] a: i32
211     ) {}
212 }
213
214 fn main() {
215     let _: unsafe extern "C" fn(_, _, _, ...) = ffi;
216     let _: fn(_, _, _, _) = foo;
217     let _: FnType = |_, _, _, _| {};
218     let c = |
219         #[allow(C)] a: u32,
220         #[cfg(something)] b: i32,
221         #[cfg_attr(something, cfg(nothing))]
222         #[deny(C)] c: i32,
223     | {};
224     let _ = c(1, 2);
225 }