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