]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-stability-deprecated.rs
9bc2c021904aad24dee2886f8a9cf2b8db797e5a
[rust.git] / src / test / compile-fail / lint-stability-deprecated.rs
1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // aux-build:lint_stability.rs
12 // aux-build:inherited_stability.rs
13 // aux-build:stability_cfg1.rs
14 // aux-build:stability_cfg2.rs
15
16 #![warn(deprecated)]
17 #![allow(dead_code, unused_extern_crates)]
18 #![feature(staged_api, test_feature, rustc_attrs)]
19
20 #![stable(feature = "rust1", since = "1.0.0")]
21
22 #[macro_use]
23 extern crate lint_stability;
24
25 mod cross_crate {
26     extern crate stability_cfg1;
27     extern crate stability_cfg2;
28
29     use lint_stability::*;
30
31     fn test() {
32         type Foo = MethodTester;
33         let foo = MethodTester;
34
35         deprecated(); //~ WARN use of deprecated item
36         foo.method_deprecated(); //~ WARN use of deprecated item
37         Foo::method_deprecated(&foo); //~ WARN use of deprecated item
38         <Foo>::method_deprecated(&foo); //~ WARN use of deprecated item
39         foo.trait_deprecated(); //~ WARN use of deprecated item
40         Trait::trait_deprecated(&foo); //~ WARN use of deprecated item
41         <Foo>::trait_deprecated(&foo); //~ WARN use of deprecated item
42         <Foo as Trait>::trait_deprecated(&foo); //~ WARN use of deprecated item
43
44         deprecated_text(); //~ WARN use of deprecated item: text
45         foo.method_deprecated_text(); //~ WARN use of deprecated item: text
46         Foo::method_deprecated_text(&foo); //~ WARN use of deprecated item: text
47         <Foo>::method_deprecated_text(&foo); //~ WARN use of deprecated item: text
48         foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
49         Trait::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
50         <Foo>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
51         <Foo as Trait>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
52
53         deprecated_unstable(); //~ WARN use of deprecated item
54         foo.method_deprecated_unstable(); //~ WARN use of deprecated item
55         Foo::method_deprecated_unstable(&foo); //~ WARN use of deprecated item
56         <Foo>::method_deprecated_unstable(&foo); //~ WARN use of deprecated item
57         foo.trait_deprecated_unstable(); //~ WARN use of deprecated item
58         Trait::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
59         <Foo>::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
60         <Foo as Trait>::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
61
62         deprecated_unstable_text(); //~ WARN use of deprecated item: text
63         foo.method_deprecated_unstable_text(); //~ WARN use of deprecated item: text
64         Foo::method_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
65         <Foo>::method_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
66         foo.trait_deprecated_unstable_text(); //~ WARN use of deprecated item: text
67         Trait::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
68         <Foo>::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
69         <Foo as Trait>::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
70
71         unstable();
72         foo.method_unstable();
73         Foo::method_unstable(&foo);
74         <Foo>::method_unstable(&foo);
75         foo.trait_unstable();
76         Trait::trait_unstable(&foo);
77         <Foo>::trait_unstable(&foo);
78         <Foo as Trait>::trait_unstable(&foo);
79
80         unstable_text();
81         foo.method_unstable_text();
82         Foo::method_unstable_text(&foo);
83         <Foo>::method_unstable_text(&foo);
84         foo.trait_unstable_text();
85         Trait::trait_unstable_text(&foo);
86         <Foo>::trait_unstable_text(&foo);
87         <Foo as Trait>::trait_unstable_text(&foo);
88
89         stable();
90         foo.method_stable();
91         Foo::method_stable(&foo);
92         <Foo>::method_stable(&foo);
93         foo.trait_stable();
94         Trait::trait_stable(&foo);
95         <Foo>::trait_stable(&foo);
96         <Foo as Trait>::trait_stable(&foo);
97
98         stable_text();
99         foo.method_stable_text();
100         Foo::method_stable_text(&foo);
101         <Foo>::method_stable_text(&foo);
102         foo.trait_stable_text();
103         Trait::trait_stable_text(&foo);
104         <Foo>::trait_stable_text(&foo);
105         <Foo as Trait>::trait_stable_text(&foo);
106
107         struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
108         struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
109         //~^ WARN use of deprecated item
110
111         let _ = DeprecatedStruct { //~ WARN use of deprecated item
112             i: 0 //~ WARN use of deprecated item
113         };
114         let _ = DeprecatedUnstableStruct {
115             //~^ WARN use of deprecated item
116             i: 0 //~ WARN use of deprecated item
117         };
118         let _ = UnstableStruct { i: 0 };
119         let _ = StableStruct { i: 0 };
120
121         let _ = DeprecatedUnitStruct; //~ WARN use of deprecated item
122         let _ = DeprecatedUnstableUnitStruct; //~ WARN use of deprecated item
123         let _ = UnstableUnitStruct;
124         let _ = StableUnitStruct;
125
126         let _ = Enum::DeprecatedVariant; //~ WARN use of deprecated item
127         let _ = Enum::DeprecatedUnstableVariant; //~ WARN use of deprecated item
128         let _ = Enum::UnstableVariant;
129         let _ = Enum::StableVariant;
130
131         let _ = DeprecatedTupleStruct (1); //~ WARN use of deprecated item
132         let _ = DeprecatedUnstableTupleStruct (1); //~ WARN use of deprecated item
133         let _ = UnstableTupleStruct (1);
134         let _ = StableTupleStruct (1);
135
136         // At the moment, the lint checker only checks stability in
137         // in the arguments of macros.
138         // Eventually, we will want to lint the contents of the
139         // macro in the module *defining* it. Also, stability levels
140         // on macros themselves are not yet linted.
141         macro_test_arg!(deprecated_text()); //~ WARN use of deprecated item: text
142         macro_test_arg!(deprecated_unstable_text()); //~ WARN use of deprecated item: text
143         macro_test_arg!(macro_test_arg!(deprecated_text())); //~ WARN use of deprecated item: text
144     }
145
146     fn test_method_param<Foo: Trait>(foo: Foo) {
147         foo.trait_deprecated(); //~ WARN use of deprecated item
148         Trait::trait_deprecated(&foo); //~ WARN use of deprecated item
149         <Foo>::trait_deprecated(&foo); //~ WARN use of deprecated item
150         <Foo as Trait>::trait_deprecated(&foo); //~ WARN use of deprecated item
151         foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
152         Trait::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
153         <Foo>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
154         <Foo as Trait>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
155         foo.trait_deprecated_unstable(); //~ WARN use of deprecated item
156         Trait::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
157         <Foo>::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
158         <Foo as Trait>::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
159         foo.trait_deprecated_unstable_text(); //~ WARN use of deprecated item: text
160         Trait::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
161         <Foo>::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
162         <Foo as Trait>::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
163         foo.trait_unstable();
164         Trait::trait_unstable(&foo);
165         <Foo>::trait_unstable(&foo);
166         <Foo as Trait>::trait_unstable(&foo);
167         foo.trait_unstable_text();
168         Trait::trait_unstable_text(&foo);
169         <Foo>::trait_unstable_text(&foo);
170         <Foo as Trait>::trait_unstable_text(&foo);
171         foo.trait_stable();
172         Trait::trait_stable(&foo);
173         <Foo>::trait_stable(&foo);
174         <Foo as Trait>::trait_stable(&foo);
175     }
176
177     fn test_method_object(foo: &Trait) {
178         foo.trait_deprecated(); //~ WARN use of deprecated item
179         foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
180         foo.trait_deprecated_unstable(); //~ WARN use of deprecated item
181         foo.trait_deprecated_unstable_text(); //~ WARN use of deprecated item: text
182         foo.trait_unstable();
183         foo.trait_unstable_text();
184         foo.trait_stable();
185     }
186
187     struct S;
188
189     impl UnstableTrait for S { }
190     impl DeprecatedTrait for S {} //~ WARN use of deprecated item: text
191     trait LocalTrait : UnstableTrait { }
192     trait LocalTrait2 : DeprecatedTrait { } //~ WARN use of deprecated item: text
193
194     impl Trait for S {
195         fn trait_stable(&self) {}
196         fn trait_unstable(&self) {}
197     }
198 }
199
200 mod inheritance {
201     extern crate inherited_stability;
202     use self::inherited_stability::*;
203
204     fn test_inheritance() {
205         unstable();
206         stable();
207
208         stable_mod::unstable();
209         stable_mod::stable();
210
211         unstable_mod::deprecated(); //~ WARN use of deprecated item
212         unstable_mod::unstable();
213
214         let _ = Unstable::UnstableVariant;
215         let _ = Unstable::StableVariant;
216
217         let x: usize = 0;
218         x.unstable();
219         x.stable();
220     }
221 }
222
223 mod this_crate {
224     #[unstable(feature = "test_feature", issue = "0")]
225     #[rustc_deprecated(since = "1.0.0", reason = "text")]
226     pub fn deprecated() {}
227     #[unstable(feature = "test_feature", issue = "0")]
228     #[rustc_deprecated(since = "1.0.0", reason = "text")]
229     pub fn deprecated_text() {}
230
231     #[unstable(feature = "test_feature", issue = "0")]
232     pub fn unstable() {}
233     #[unstable(feature = "test_feature", reason = "text", issue = "0")]
234     pub fn unstable_text() {}
235
236     #[stable(feature = "rust1", since = "1.0.0")]
237     pub fn stable() {}
238     #[stable(feature = "rust1", since = "1.0.0")]
239     pub fn stable_text() {}
240
241     #[stable(feature = "rust1", since = "1.0.0")]
242     pub struct MethodTester;
243
244     impl MethodTester {
245         #[unstable(feature = "test_feature", issue = "0")]
246         #[rustc_deprecated(since = "1.0.0", reason = "text")]
247         pub fn method_deprecated(&self) {}
248         #[unstable(feature = "test_feature", issue = "0")]
249         #[rustc_deprecated(since = "1.0.0", reason = "text")]
250         pub fn method_deprecated_text(&self) {}
251
252         #[unstable(feature = "test_feature", issue = "0")]
253         pub fn method_unstable(&self) {}
254         #[unstable(feature = "test_feature", reason = "text", issue = "0")]
255         pub fn method_unstable_text(&self) {}
256
257         #[stable(feature = "rust1", since = "1.0.0")]
258         pub fn method_stable(&self) {}
259         #[stable(feature = "rust1", since = "1.0.0")]
260         pub fn method_stable_text(&self) {}
261     }
262
263     pub trait Trait {
264         #[unstable(feature = "test_feature", issue = "0")]
265         #[rustc_deprecated(since = "1.0.0", reason = "text")]
266         fn trait_deprecated(&self) {}
267         #[unstable(feature = "test_feature", issue = "0")]
268         #[rustc_deprecated(since = "1.0.0", reason = "text")]
269         fn trait_deprecated_text(&self) {}
270
271         #[unstable(feature = "test_feature", issue = "0")]
272         fn trait_unstable(&self) {}
273         #[unstable(feature = "test_feature", reason = "text", issue = "0")]
274         fn trait_unstable_text(&self) {}
275
276         #[stable(feature = "rust1", since = "1.0.0")]
277         fn trait_stable(&self) {}
278         #[stable(feature = "rust1", since = "1.0.0")]
279         fn trait_stable_text(&self) {}
280     }
281
282     impl Trait for MethodTester {}
283
284     #[unstable(feature = "test_feature", issue = "0")]
285     #[rustc_deprecated(since = "1.0.0", reason = "text")]
286     pub struct DeprecatedStruct {
287         #[stable(feature = "test_feature", since = "1.0.0")] i: isize
288     }
289     #[unstable(feature = "test_feature", issue = "0")]
290     pub struct UnstableStruct {
291         #[stable(feature = "test_feature", since = "1.0.0")] i: isize
292     }
293     #[stable(feature = "rust1", since = "1.0.0")]
294     pub struct StableStruct {
295         #[stable(feature = "test_feature", since = "1.0.0")] i: isize
296     }
297
298     #[unstable(feature = "test_feature", issue = "0")]
299     #[rustc_deprecated(since = "1.0.0", reason = "text")]
300     pub struct DeprecatedUnitStruct;
301     #[unstable(feature = "test_feature", issue = "0")]
302     pub struct UnstableUnitStruct;
303     #[stable(feature = "rust1", since = "1.0.0")]
304     pub struct StableUnitStruct;
305
306     pub enum Enum {
307         #[unstable(feature = "test_feature", issue = "0")]
308         #[rustc_deprecated(since = "1.0.0", reason = "text")]
309         DeprecatedVariant,
310         #[unstable(feature = "test_feature", issue = "0")]
311         UnstableVariant,
312
313         #[stable(feature = "rust1", since = "1.0.0")]
314         StableVariant,
315     }
316
317     #[unstable(feature = "test_feature", issue = "0")]
318     #[rustc_deprecated(since = "1.0.0", reason = "text")]
319     pub struct DeprecatedTupleStruct(isize);
320     #[unstable(feature = "test_feature", issue = "0")]
321     pub struct UnstableTupleStruct(isize);
322     #[stable(feature = "rust1", since = "1.0.0")]
323     pub struct StableTupleStruct(isize);
324
325     fn test() {
326         // Only the deprecated cases of the following should generate
327         // errors, because other stability attributes now have meaning
328         // only *across* crates, not within a single crate.
329
330         type Foo = MethodTester;
331         let foo = MethodTester;
332
333         deprecated(); //~ WARN use of deprecated item
334         foo.method_deprecated(); //~ WARN use of deprecated item
335         Foo::method_deprecated(&foo); //~ WARN use of deprecated item
336         <Foo>::method_deprecated(&foo); //~ WARN use of deprecated item
337         foo.trait_deprecated(); //~ WARN use of deprecated item
338         Trait::trait_deprecated(&foo); //~ WARN use of deprecated item
339         <Foo>::trait_deprecated(&foo); //~ WARN use of deprecated item
340         <Foo as Trait>::trait_deprecated(&foo); //~ WARN use of deprecated item
341
342         deprecated_text(); //~ WARN use of deprecated item: text
343         foo.method_deprecated_text(); //~ WARN use of deprecated item: text
344         Foo::method_deprecated_text(&foo); //~ WARN use of deprecated item: text
345         <Foo>::method_deprecated_text(&foo); //~ WARN use of deprecated item: text
346         foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
347         Trait::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
348         <Foo>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
349         <Foo as Trait>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
350
351         unstable();
352         foo.method_unstable();
353         Foo::method_unstable(&foo);
354         <Foo>::method_unstable(&foo);
355         foo.trait_unstable();
356         Trait::trait_unstable(&foo);
357         <Foo>::trait_unstable(&foo);
358         <Foo as Trait>::trait_unstable(&foo);
359
360         unstable_text();
361         foo.method_unstable_text();
362         Foo::method_unstable_text(&foo);
363         <Foo>::method_unstable_text(&foo);
364         foo.trait_unstable_text();
365         Trait::trait_unstable_text(&foo);
366         <Foo>::trait_unstable_text(&foo);
367         <Foo as Trait>::trait_unstable_text(&foo);
368
369         stable();
370         foo.method_stable();
371         Foo::method_stable(&foo);
372         <Foo>::method_stable(&foo);
373         foo.trait_stable();
374         Trait::trait_stable(&foo);
375         <Foo>::trait_stable(&foo);
376         <Foo as Trait>::trait_stable(&foo);
377
378         stable_text();
379         foo.method_stable_text();
380         Foo::method_stable_text(&foo);
381         <Foo>::method_stable_text(&foo);
382         foo.trait_stable_text();
383         Trait::trait_stable_text(&foo);
384         <Foo>::trait_stable_text(&foo);
385         <Foo as Trait>::trait_stable_text(&foo);
386
387         let _ = DeprecatedStruct {
388             //~^ WARN use of deprecated item
389             i: 0 //~ WARN use of deprecated item
390         };
391         let _ = UnstableStruct { i: 0 };
392         let _ = StableStruct { i: 0 };
393
394         let _ = DeprecatedUnitStruct; //~ WARN use of deprecated item
395         let _ = UnstableUnitStruct;
396         let _ = StableUnitStruct;
397
398         let _ = Enum::DeprecatedVariant; //~ WARN use of deprecated item
399         let _ = Enum::UnstableVariant;
400         let _ = Enum::StableVariant;
401
402         let _ = DeprecatedTupleStruct (1); //~ WARN use of deprecated item
403         let _ = UnstableTupleStruct (1);
404         let _ = StableTupleStruct (1);
405     }
406
407     fn test_method_param<Foo: Trait>(foo: Foo) {
408         foo.trait_deprecated(); //~ WARN use of deprecated item
409         Trait::trait_deprecated(&foo); //~ WARN use of deprecated item
410         <Foo>::trait_deprecated(&foo); //~ WARN use of deprecated item
411         <Foo as Trait>::trait_deprecated(&foo); //~ WARN use of deprecated item
412         foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
413         Trait::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
414         <Foo>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
415         <Foo as Trait>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
416         foo.trait_unstable();
417         Trait::trait_unstable(&foo);
418         <Foo>::trait_unstable(&foo);
419         <Foo as Trait>::trait_unstable(&foo);
420         foo.trait_unstable_text();
421         Trait::trait_unstable_text(&foo);
422         <Foo>::trait_unstable_text(&foo);
423         <Foo as Trait>::trait_unstable_text(&foo);
424         foo.trait_stable();
425         Trait::trait_stable(&foo);
426         <Foo>::trait_stable(&foo);
427         <Foo as Trait>::trait_stable(&foo);
428     }
429
430     fn test_method_object(foo: &Trait) {
431         foo.trait_deprecated(); //~ WARN use of deprecated item
432         foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
433         foo.trait_unstable();
434         foo.trait_unstable_text();
435         foo.trait_stable();
436     }
437
438     #[unstable(feature = "test_feature", issue = "0")]
439     #[rustc_deprecated(since = "1.0.0", reason = "text")]
440     fn test_fn_body() {
441         fn fn_in_body() {}
442         fn_in_body(); //~ WARN use of deprecated item: text
443     }
444
445     impl MethodTester {
446         #[unstable(feature = "test_feature", issue = "0")]
447         #[rustc_deprecated(since = "1.0.0", reason = "text")]
448         fn test_method_body(&self) {
449             fn fn_in_body() {}
450             fn_in_body(); //~ WARN use of deprecated item: text
451         }
452     }
453
454     #[unstable(feature = "test_feature", issue = "0")]
455     #[rustc_deprecated(since = "1.0.0", reason = "text")]
456     pub trait DeprecatedTrait {
457         fn dummy(&self) { }
458     }
459
460     struct S;
461
462     impl DeprecatedTrait for S { } //~ WARN use of deprecated item
463
464     trait LocalTrait : DeprecatedTrait { } //~ WARN use of deprecated item
465 }
466
467 #[rustc_error] fn main() {} //~ ERROR: compilation successful