]> git.lizzy.rs Git - rust.git/blob - src/test/ui/deprecation/deprecation-lint.rs
26271395005a782d617020c94d0caad03ded82c4
[rust.git] / src / test / ui / deprecation / deprecation-lint.rs
1 // aux-build:deprecation-lint.rs
2 // ignore-tidy-linelength
3
4 #![deny(deprecated)]
5 #![allow(warnings)]
6
7 #[macro_use]
8 extern crate deprecation_lint;
9
10 mod cross_crate {
11     use deprecation_lint::*;
12
13     fn test() {
14         type Foo = MethodTester;
15         let foo = MethodTester;
16
17         deprecated(); //~ ERROR use of deprecated item 'deprecation_lint::deprecated'
18         foo.method_deprecated(); //~ ERROR use of deprecated item 'deprecation_lint::MethodTester::method_deprecated'
19         Foo::method_deprecated(&foo); //~ ERROR use of deprecated item 'deprecation_lint::MethodTester::method_deprecated'
20         <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated item 'deprecation_lint::MethodTester::method_deprecated'
21         foo.trait_deprecated(); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
22         Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
23         <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
24         <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
25
26         deprecated_text(); //~ ERROR use of deprecated item 'deprecation_lint::deprecated_text': text
27         foo.method_deprecated_text(); //~ ERROR use of deprecated item 'deprecation_lint::MethodTester::method_deprecated_text': text
28         Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated item 'deprecation_lint::MethodTester::method_deprecated_text': text
29         <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated item 'deprecation_lint::MethodTester::method_deprecated_text': text
30         foo.trait_deprecated_text(); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
31         Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
32         <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
33         <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
34
35         let _ = DeprecatedStruct { //~ ERROR use of deprecated item 'deprecation_lint::DeprecatedStruct': text
36             i: 0 //~ ERROR use of deprecated item 'deprecation_lint::DeprecatedStruct::i': text
37         };
38
39         let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item 'deprecation_lint::DeprecatedUnitStruct': text
40
41         let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item 'deprecation_lint::Enum::DeprecatedVariant': text
42
43         let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item 'deprecation_lint::DeprecatedTupleStruct': text
44
45         let _ = nested::DeprecatedStruct { //~ ERROR use of deprecated item 'deprecation_lint::nested::DeprecatedStruct': text
46             i: 0 //~ ERROR use of deprecated item 'deprecation_lint::nested::DeprecatedStruct::i': text
47         };
48
49         let _ = nested::DeprecatedUnitStruct; //~ ERROR use of deprecated item 'deprecation_lint::nested::DeprecatedUnitStruct': text
50
51         let _ = nested::Enum::DeprecatedVariant; //~ ERROR use of deprecated item 'deprecation_lint::nested::Enum::DeprecatedVariant': text
52
53         let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated item 'deprecation_lint::nested::DeprecatedTupleStruct': text
54
55         // At the moment, the lint checker only checks stability in
56         // in the arguments of macros.
57         // Eventually, we will want to lint the contents of the
58         // macro in the module *defining* it. Also, stability levels
59         // on macros themselves are not yet linted.
60         macro_test_arg!(deprecated_text()); //~ ERROR use of deprecated item 'deprecation_lint::deprecated_text': text
61         macro_test_arg!(macro_test_arg!(deprecated_text())); //~ ERROR use of deprecated item 'deprecation_lint::deprecated_text': text
62     }
63
64     fn test_method_param<Foo: Trait>(foo: Foo) {
65         foo.trait_deprecated(); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
66         Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
67         <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
68         <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
69         foo.trait_deprecated_text(); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
70         Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
71         <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
72         <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
73     }
74
75     fn test_method_object(foo: &Trait) {
76         foo.trait_deprecated(); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated'
77         foo.trait_deprecated_text(); //~ ERROR use of deprecated item 'deprecation_lint::Trait::trait_deprecated_text': text
78     }
79
80     struct S;
81
82     impl DeprecatedTrait for S {} //~ ERROR use of deprecated item 'deprecation_lint::DeprecatedTrait': text
83     trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item 'deprecation_lint::DeprecatedTrait': text
84
85     pub fn foo() {
86         let x = Stable {
87             override2: 3,
88             //~^ ERROR use of deprecated item 'deprecation_lint::Stable::override2': text
89         };
90
91         let _ = x.override2;
92         //~^ ERROR use of deprecated item 'deprecation_lint::Stable::override2': text
93
94         let Stable {
95             override2: _
96             //~^ ERROR use of deprecated item 'deprecation_lint::Stable::override2': text
97         } = x;
98         // all fine
99         let Stable { .. } = x;
100
101         let x = Stable2(1, 2, 3);
102
103         let _ = x.2;
104         //~^ ERROR use of deprecated item 'deprecation_lint::Stable2::2': text
105
106         let Stable2(_,
107                    _,
108                    _)
109             //~^ ERROR use of deprecated item 'deprecation_lint::Stable2::2': text
110             = x;
111         // all fine
112         let Stable2(..) = x;
113
114         let x = Deprecated {
115             //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated': text
116             inherit: 1,
117             //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated::inherit': text
118         };
119
120         let _ = x.inherit;
121         //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated::inherit': text
122
123         let Deprecated {
124             //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated': text
125             inherit: _,
126             //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated::inherit': text
127         } = x;
128
129         let Deprecated
130             //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated': text
131             { .. } = x;
132
133         let x = Deprecated2(1, 2, 3);
134         //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2': text
135
136         let _ = x.0;
137         //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2::0': text
138         let _ = x.1;
139         //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2::1': text
140         let _ = x.2;
141         //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2::2': text
142
143         let Deprecated2
144         //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2': text
145             (_,
146              //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2::0': text
147              _,
148              //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2::1': text
149              _)
150              //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2::2': text
151             = x;
152         let Deprecated2
153         //~^ ERROR use of deprecated item 'deprecation_lint::Deprecated2': text
154             // the patterns are all fine:
155             (..) = x;
156     }
157 }
158
159 mod inheritance {
160     use deprecation_lint::*;
161
162     fn test_inheritance() {
163         deprecated_mod::deprecated(); //~ ERROR use of deprecated item 'deprecation_lint::deprecated_mod::deprecated': text
164     }
165 }
166
167 mod this_crate {
168     #[deprecated(since = "1.0.0", note = "text")]
169     pub fn deprecated() {}
170     #[deprecated(since = "1.0.0", note = "text")]
171     pub fn deprecated_text() {}
172
173     #[deprecated(since = "99.99.99", note = "text")]
174     pub fn deprecated_future() {}
175     #[deprecated(since = "99.99.99", note = "text")]
176     pub fn deprecated_future_text() {}
177
178     pub struct MethodTester;
179
180     impl MethodTester {
181         #[deprecated(since = "1.0.0", note = "text")]
182         pub fn method_deprecated(&self) {}
183         #[deprecated(since = "1.0.0", note = "text")]
184         pub fn method_deprecated_text(&self) {}
185     }
186
187     pub trait Trait {
188         #[deprecated(since = "1.0.0", note = "text")]
189         fn trait_deprecated(&self) {}
190         #[deprecated(since = "1.0.0", note = "text")]
191         fn trait_deprecated_text(&self) {}
192     }
193
194     impl Trait for MethodTester {}
195
196     #[deprecated(since = "1.0.0", note = "text")]
197     pub struct DeprecatedStruct {
198         i: isize
199     }
200     pub struct UnstableStruct {
201         i: isize
202     }
203     pub struct StableStruct {
204         i: isize
205     }
206
207     #[deprecated(since = "1.0.0", note = "text")]
208     pub struct DeprecatedUnitStruct;
209
210     pub enum Enum {
211         #[deprecated(since = "1.0.0", note = "text")]
212         DeprecatedVariant,
213     }
214
215     #[deprecated(since = "1.0.0", note = "text")]
216     pub struct DeprecatedTupleStruct(isize);
217
218     mod nested {
219         #[deprecated(since = "1.0.0", note = "text")]
220         pub struct DeprecatedStruct {
221             i: isize
222         }
223
224         #[deprecated(since = "1.0.0", note = "text")]
225         pub struct DeprecatedUnitStruct;
226
227         pub enum Enum {
228             #[deprecated(since = "1.0.0", note = "text")]
229             DeprecatedVariant,
230         }
231
232         #[deprecated(since = "1.0.0", note = "text")]
233         pub struct DeprecatedTupleStruct(pub isize);
234     }
235
236     fn test() {
237         use self::nested;
238
239         // Only the deprecated cases of the following should generate
240         // errors, because other stability attributes now have meaning
241         // only *across* crates, not within a single crate.
242
243         type Foo = MethodTester;
244         let foo = MethodTester;
245
246         deprecated(); //~ ERROR use of deprecated item 'this_crate::deprecated'
247         foo.method_deprecated(); //~ ERROR use of deprecated item 'this_crate::MethodTester::method_deprecated'
248         Foo::method_deprecated(&foo); //~ ERROR use of deprecated item 'this_crate::MethodTester::method_deprecated'
249         <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated item 'this_crate::MethodTester::method_deprecated'
250         foo.trait_deprecated(); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
251         Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
252         <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
253         <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
254
255         deprecated_text(); //~ ERROR use of deprecated item 'this_crate::deprecated_text': text
256         foo.method_deprecated_text(); //~ ERROR use of deprecated item 'this_crate::MethodTester::method_deprecated_text': text
257         Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::MethodTester::method_deprecated_text': text
258         <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::MethodTester::method_deprecated_text': text
259         foo.trait_deprecated_text(); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
260         Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
261         <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
262         <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
263
264         // Future deprecations are only permitted for rustc_deprecated.
265         deprecated_future(); //~ ERROR use of deprecated item
266         deprecated_future_text(); //~ ERROR use of deprecated item
267
268         let _ = DeprecatedStruct {
269             //~^ ERROR use of deprecated item 'this_crate::DeprecatedStruct': text
270             i: 0 //~ ERROR use of deprecated item 'this_crate::DeprecatedStruct::i': text
271         };
272
273         let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item 'this_crate::DeprecatedUnitStruct': text
274
275         let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item 'this_crate::Enum::DeprecatedVariant': text
276
277         let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item 'this_crate::DeprecatedTupleStruct': text
278
279         let _ = nested::DeprecatedStruct {
280             //~^ ERROR use of deprecated item 'this_crate::nested::DeprecatedStruct': text
281             i: 0 //~ ERROR use of deprecated item 'this_crate::nested::DeprecatedStruct::i': text
282         };
283
284         let _ = nested::DeprecatedUnitStruct; //~ ERROR use of deprecated item 'this_crate::nested::DeprecatedUnitStruct': text
285
286         let _ = nested::Enum::DeprecatedVariant; //~ ERROR use of deprecated item 'this_crate::nested::Enum::DeprecatedVariant': text
287
288         let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated item 'this_crate::nested::DeprecatedTupleStruct': text
289     }
290
291     fn test_method_param<Foo: Trait>(foo: Foo) {
292         foo.trait_deprecated(); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
293         Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
294         <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
295         <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
296         foo.trait_deprecated_text(); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
297         Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
298         <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
299         <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
300     }
301
302     fn test_method_object(foo: &Trait) {
303         foo.trait_deprecated(); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated'
304         foo.trait_deprecated_text(); //~ ERROR use of deprecated item '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 item '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 item 'this_crate::DeprecatedTrait': text
337
338     trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item '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 item 'this_crate2::Stable::override2': text
365         };
366
367         let _ = x.override2;
368         //~^ ERROR use of deprecated item 'this_crate2::Stable::override2': text
369
370         let Stable {
371             override2: _
372             //~^ ERROR use of deprecated item '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 item 'this_crate2::Stable2::2': text
381
382         let Stable2(_,
383                    _,
384                    _)
385             //~^ ERROR use of deprecated item 'this_crate2::Stable2::2': text
386             = x;
387         // all fine
388         let Stable2(..) = x;
389
390         let x = Deprecated {
391             //~^ ERROR use of deprecated item 'this_crate2::Deprecated': text
392             inherit: 1,
393             //~^ ERROR use of deprecated item 'this_crate2::Deprecated::inherit': text
394         };
395
396         let _ = x.inherit;
397         //~^ ERROR use of deprecated item 'this_crate2::Deprecated::inherit': text
398
399         let Deprecated {
400             //~^ ERROR use of deprecated item 'this_crate2::Deprecated': text
401             inherit: _,
402             //~^ ERROR use of deprecated item 'this_crate2::Deprecated::inherit': text
403         } = x;
404
405         let Deprecated
406             //~^ ERROR use of deprecated item '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 item 'this_crate2::Deprecated2': text
412
413         let _ = x.0;
414         //~^ ERROR use of deprecated item 'this_crate2::Deprecated2::0': text
415         let _ = x.1;
416         //~^ ERROR use of deprecated item 'this_crate2::Deprecated2::1': text
417         let _ = x.2;
418         //~^ ERROR use of deprecated item 'this_crate2::Deprecated2::2': text
419
420         let Deprecated2
421         //~^ ERROR use of deprecated item 'this_crate2::Deprecated2': text
422             (_,
423              //~^ ERROR use of deprecated item 'this_crate2::Deprecated2::0': text
424              _,
425              //~^ ERROR use of deprecated item 'this_crate2::Deprecated2::1': text
426              _)
427             //~^ ERROR use of deprecated item 'this_crate2::Deprecated2::2': text
428             = x;
429         let Deprecated2
430         //~^ ERROR use of deprecated item 'this_crate2::Deprecated2': text
431             // the patterns are all fine:
432             (..) = x;
433     }
434 }
435
436 fn main() {}