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