]> git.proxmox.com Git - rustc.git/blob - src/test/ui/deprecation/deprecation-lint.rs
Update upstream source from tag 'upstream/1.62.1+dfsg1'
[rustc.git] / src / test / ui / deprecation / deprecation-lint.rs
1 // aux-build:deprecation-lint.rs
2
3 #![deny(deprecated)]
4 #![allow(warnings)]
5
6 #[macro_use]
7 extern crate deprecation_lint;
8
9 mod cross_crate {
10 use deprecation_lint::*;
11
12 fn test() {
13 type Foo = MethodTester;
14 let foo = MethodTester;
15
16 deprecated(); //~ ERROR use of deprecated function `deprecation_lint::deprecated`
17 foo.method_deprecated(); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`
18 Foo::method_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`
19 <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`
20 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
21 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
22 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
23 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
24
25 deprecated_text(); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
26 foo.method_deprecated_text(); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
27 Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
28 <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
29 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
30 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
31 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
32 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
33
34 let _ = DeprecatedStruct { //~ ERROR use of deprecated struct `deprecation_lint::DeprecatedStruct`: text
35 i: 0 //~ ERROR use of deprecated field `deprecation_lint::DeprecatedStruct::i`: text
36 };
37
38 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `deprecation_lint::DeprecatedUnitStruct`: text
39
40 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `deprecation_lint::Enum::DeprecatedVariant`: text
41
42 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `deprecation_lint::DeprecatedTupleStruct`: text
43
44 let _ = nested::DeprecatedStruct { //~ ERROR use of deprecated struct `deprecation_lint::nested::DeprecatedStruct`: text
45 i: 0 //~ ERROR use of deprecated field `deprecation_lint::nested::DeprecatedStruct::i`: text
46 };
47
48 let _ = nested::DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `deprecation_lint::nested::DeprecatedUnitStruct`: text
49
50 let _ = nested::Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `deprecation_lint::nested::Enum::DeprecatedVariant`: text
51
52 let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `deprecation_lint::nested::DeprecatedTupleStruct`: text
53
54 // At the moment, the lint checker only checks stability in
55 // in the arguments of macros.
56 // Eventually, we will want to lint the contents of the
57 // macro in the module *defining* it. Also, stability levels
58 // on macros themselves are not yet linted.
59 macro_test_arg!(deprecated_text()); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
60 macro_test_arg!(macro_test_arg!(deprecated_text())); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
61 }
62
63 fn test_method_param<Foo: Trait>(foo: Foo) {
64 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
65 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
66 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
67 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
68 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
69 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
70 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
71 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
72 }
73
74 fn test_method_object(foo: &Trait) {
75 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
76 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
77 }
78
79 struct S;
80
81 impl DeprecatedTrait for S {} //~ ERROR use of deprecated trait `deprecation_lint::DeprecatedTrait`: text
82 trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated trait `deprecation_lint::DeprecatedTrait`: text
83
84 pub fn foo() {
85 let x = Stable {
86 override2: 3,
87 //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text
88 };
89
90 let _ = x.override2;
91 //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text
92
93 let Stable {
94 override2: _
95 //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text
96 } = x;
97 // all fine
98 let Stable { .. } = x;
99
100 let x = Stable2(1, 2, 3);
101
102 let _ = x.2;
103 //~^ ERROR use of deprecated field `deprecation_lint::Stable2::2`: text
104
105 let Stable2(_,
106 _,
107 _)
108 //~^ ERROR use of deprecated field `deprecation_lint::Stable2::2`: text
109 = x;
110 // all fine
111 let Stable2(..) = x;
112
113 let x = Deprecated {
114 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
115 inherit: 1,
116 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text
117 };
118
119 let _ = x.inherit;
120 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text
121
122 let Deprecated {
123 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
124 inherit: _,
125 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text
126 } = x;
127
128 let Deprecated
129 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
130 { .. } = x;
131
132 let x = Deprecated2(1, 2, 3);
133 //~^ ERROR use of deprecated tuple struct `deprecation_lint::Deprecated2`: text
134
135 let _ = x.0;
136 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::0`: text
137 let _ = x.1;
138 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::1`: text
139 let _ = x.2;
140 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::2`: text
141
142 let Deprecated2
143 //~^ ERROR use of deprecated tuple struct `deprecation_lint::Deprecated2`: text
144 (_,
145 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::0`: text
146 _,
147 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::1`: text
148 _)
149 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::2`: text
150 = x;
151 let Deprecated2
152 //~^ ERROR use of deprecated tuple struct `deprecation_lint::Deprecated2`: text
153 // the patterns are all fine:
154 (..) = x;
155 }
156 }
157
158 mod inheritance {
159 use deprecation_lint::*;
160
161 fn test_inheritance() {
162 deprecated_mod::deprecated(); //~ ERROR use of deprecated function `deprecation_lint::deprecated_mod::deprecated`: text
163 }
164 }
165
166 mod this_crate {
167 #[deprecated(since = "1.0.0", note = "text")]
168 pub fn deprecated() {}
169 #[deprecated(since = "1.0.0", note = "text")]
170 pub fn deprecated_text() {}
171
172 #[deprecated(since = "99.99.99", note = "text")]
173 pub fn deprecated_future() {}
174 #[deprecated(since = "99.99.99", note = "text")]
175 pub fn deprecated_future_text() {}
176
177 pub struct MethodTester;
178
179 impl MethodTester {
180 #[deprecated(since = "1.0.0", note = "text")]
181 pub fn method_deprecated(&self) {}
182 #[deprecated(since = "1.0.0", note = "text")]
183 pub fn method_deprecated_text(&self) {}
184 }
185
186 pub trait Trait {
187 #[deprecated(since = "1.0.0", note = "text")]
188 fn trait_deprecated(&self) {}
189 #[deprecated(since = "1.0.0", note = "text")]
190 fn trait_deprecated_text(&self) {}
191 }
192
193 impl Trait for MethodTester {}
194
195 #[deprecated(since = "1.0.0", note = "text")]
196 pub struct DeprecatedStruct {
197 i: isize
198 }
199 pub struct UnstableStruct {
200 i: isize
201 }
202 pub struct StableStruct {
203 i: isize
204 }
205
206 #[deprecated(since = "1.0.0", note = "text")]
207 pub struct DeprecatedUnitStruct;
208
209 pub enum Enum {
210 #[deprecated(since = "1.0.0", note = "text")]
211 DeprecatedVariant,
212 }
213
214 #[deprecated(since = "1.0.0", note = "text")]
215 pub struct DeprecatedTupleStruct(isize);
216
217 mod nested {
218 #[deprecated(since = "1.0.0", note = "text")]
219 pub struct DeprecatedStruct {
220 i: isize
221 }
222
223 #[deprecated(since = "1.0.0", note = "text")]
224 pub struct DeprecatedUnitStruct;
225
226 pub enum Enum {
227 #[deprecated(since = "1.0.0", note = "text")]
228 DeprecatedVariant,
229 }
230
231 #[deprecated(since = "1.0.0", note = "text")]
232 pub struct DeprecatedTupleStruct(pub isize);
233 }
234
235 fn test() {
236 use self::nested;
237
238 // Only the deprecated cases of the following should generate
239 // errors, because other stability attributes now have meaning
240 // only *across* crates, not within a single crate.
241
242 type Foo = MethodTester;
243 let foo = MethodTester;
244
245 deprecated(); //~ ERROR use of deprecated function `this_crate::deprecated`
246 foo.method_deprecated(); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated`
247 Foo::method_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated`
248 <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated`
249 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
250 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
251 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
252 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
253
254 deprecated_text(); //~ ERROR use of deprecated function `this_crate::deprecated_text`: text
255 foo.method_deprecated_text(); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
256 Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
257 <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
258 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
259 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
260 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
261 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
262
263 // Future deprecations are only permitted with `#![feature(staged_api)]`
264 deprecated_future(); //~ ERROR use of deprecated function
265 deprecated_future_text(); //~ ERROR use of deprecated function
266
267 let _ = DeprecatedStruct {
268 //~^ ERROR use of deprecated struct `this_crate::DeprecatedStruct`: text
269 i: 0 //~ ERROR use of deprecated field `this_crate::DeprecatedStruct::i`: text
270 };
271
272 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `this_crate::DeprecatedUnitStruct`: text
273
274 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `this_crate::Enum::DeprecatedVariant`: text
275
276 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `this_crate::DeprecatedTupleStruct`: text
277
278 let _ = nested::DeprecatedStruct {
279 //~^ ERROR use of deprecated struct `this_crate::nested::DeprecatedStruct`: text
280 i: 0 //~ ERROR use of deprecated field `this_crate::nested::DeprecatedStruct::i`: text
281 //~| ERROR field `i` of struct `this_crate::nested::DeprecatedStruct` is private
282 };
283
284 let _ = nested::DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `this_crate::nested::DeprecatedUnitStruct`: text
285
286 let _ = nested::Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `this_crate::nested::Enum::DeprecatedVariant`: text
287
288 let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `this_crate::nested::DeprecatedTupleStruct`: text
289 }
290
291 fn test_method_param<Foo: Trait>(foo: Foo) {
292 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
293 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
294 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
295 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
296 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
297 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
298 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
299 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
300 }
301
302 fn test_method_object(foo: &Trait) {
303 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
304 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
305 }
306
307 #[deprecated(since = "1.0.0", note = "text")]
308 fn test_fn_body() {
309 fn fn_in_body() {}
310 fn_in_body();
311 }
312
313 fn test_fn_closure_body() {
314 let _ = || {
315 #[deprecated]
316 fn bar() { }
317 bar(); //~ ERROR use of deprecated function `this_crate::test_fn_closure_body::{closure#0}::bar`
318 };
319 }
320
321 impl MethodTester {
322 #[deprecated(since = "1.0.0", note = "text")]
323 fn test_method_body(&self) {
324 fn fn_in_body() {}
325 fn_in_body();
326 }
327 }
328
329 #[deprecated(since = "1.0.0", note = "text")]
330 pub trait DeprecatedTrait {
331 fn dummy(&self) { }
332 }
333
334 struct S;
335
336 impl DeprecatedTrait for S { } //~ ERROR use of deprecated trait `this_crate::DeprecatedTrait`: text
337
338 trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated trait `this_crate::DeprecatedTrait`: text
339 }
340
341 mod this_crate2 {
342 struct Stable {
343 #[deprecated(since = "1.0.0", note = "text")]
344 override2: u8,
345 }
346
347 struct Stable2(u8,
348 u8,
349 #[deprecated(since = "1.0.0", note = "text")] u8);
350
351 #[deprecated(since = "1.0.0", note = "text")]
352 struct Deprecated {
353 inherit: u8,
354 }
355
356 #[deprecated(since = "1.0.0", note = "text")]
357 struct Deprecated2(u8,
358 u8,
359 u8);
360
361 pub fn foo() {
362 let x = Stable {
363 override2: 3,
364 //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text
365 };
366
367 let _ = x.override2;
368 //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text
369
370 let Stable {
371 override2: _
372 //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text
373 } = x;
374 // all fine
375 let Stable { .. } = x;
376
377 let x = Stable2(1, 2, 3);
378
379 let _ = x.2;
380 //~^ ERROR use of deprecated field `this_crate2::Stable2::2`: text
381
382 let Stable2(_,
383 _,
384 _)
385 //~^ ERROR use of deprecated field `this_crate2::Stable2::2`: text
386 = x;
387 // all fine
388 let Stable2(..) = x;
389
390 let x = Deprecated {
391 //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
392 inherit: 1,
393 //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text
394 };
395
396 let _ = x.inherit;
397 //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text
398
399 let Deprecated {
400 //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
401 inherit: _,
402 //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text
403 } = x;
404
405 let Deprecated
406 //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
407 // the patterns are all fine:
408 { .. } = x;
409
410 let x = Deprecated2(1, 2, 3);
411 //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text
412
413 let _ = x.0;
414 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::0`: text
415 let _ = x.1;
416 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::1`: text
417 let _ = x.2;
418 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::2`: text
419
420 let Deprecated2
421 //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text
422 (_,
423 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::0`: text
424 _,
425 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::1`: text
426 _)
427 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::2`: text
428 = x;
429 let Deprecated2
430 //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text
431 // the patterns are all fine:
432 (..) = x;
433 }
434
435 #[derive(Debug)]
436 #[deprecated(note = "Use something else instead")]
437 enum DeprecatedDebugEnum {
438 Variant1 { value: Option<String> },
439 }
440
441 #[allow(deprecated)]
442 impl DeprecatedDebugEnum {
443 fn new() -> Self {
444 DeprecatedDebugEnum::Variant1 { value: None }
445 }
446 }
447
448 #[allow(deprecated)]
449 pub fn allow_dep() {
450 let _ = DeprecatedDebugEnum::new();
451 }
452 }
453
454 fn main() {}