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