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