]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-stability.rs
Auto merge of #22541 - Manishearth:rollup, r=Gankro
[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 // ignore-tidy-linelength
16
17 #![deny(deprecated)]
18 #![allow(dead_code)]
19 #![feature(staged_api)]
20 #![staged_api]
21
22 #[macro_use]
23 extern crate lint_stability;
24
25 mod cross_crate {
26     extern crate stability_cfg1;
27     extern crate stability_cfg2; //~ WARNING: use of unstable library feature
28
29     use lint_stability::*;
30
31     fn test() {
32         let foo = MethodTester;
33
34         deprecated(); //~ ERROR use of deprecated item
35         foo.method_deprecated(); //~ ERROR use of deprecated item
36         foo.trait_deprecated(); //~ ERROR use of deprecated item
37
38         deprecated_text(); //~ ERROR use of deprecated item: text
39         foo.method_deprecated_text(); //~ ERROR use of deprecated item: text
40         foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
41
42         deprecated_unstable(); //~ ERROR use of deprecated item
43         //~^ WARNING use of unstable library feature
44         foo.method_deprecated_unstable(); //~ ERROR use of deprecated item
45         //~^ WARNING use of unstable library feature
46         foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item
47         //~^ WARNING use of unstable library feature
48
49         deprecated_unstable_text(); //~ ERROR use of deprecated item: text
50         //~^ WARNING use of unstable library feature
51         foo.method_deprecated_unstable_text(); //~ ERROR use of deprecated item: text
52         //~^ WARNING use of unstable library feature
53         foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text
54         //~^ WARNING use of unstable library feature
55
56         unstable(); //~ WARNING use of unstable library feature
57         foo.method_unstable(); //~ WARNING use of unstable library feature
58         foo.trait_unstable(); //~ WARNING use of unstable library feature
59
60         unstable_text(); //~ WARNING use of unstable library feature 'test_feature': text
61         foo.method_unstable_text(); //~ WARNING use of unstable library feature 'test_feature': text
62         foo.trait_unstable_text(); //~ WARNING use of unstable library feature 'test_feature': text
63
64         stable();
65         foo.method_stable();
66         foo.trait_stable();
67
68         stable_text();
69         foo.method_stable_text();
70         foo.trait_stable_text();
71
72         let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
73         let _ = DeprecatedUnstableStruct { i: 0 }; //~ ERROR use of deprecated item
74         //~^ WARNING use of unstable library feature
75         let _ = UnstableStruct { i: 0 }; //~ WARNING use of unstable library feature
76         let _ = StableStruct { i: 0 };
77
78         let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
79         let _ = DeprecatedUnstableUnitStruct; //~ ERROR use of deprecated item
80         //~^ WARNING use of unstable library feature
81         let _ = UnstableUnitStruct; //~ WARNING use of unstable library feature
82         let _ = StableUnitStruct;
83
84         let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item
85         let _ = Enum::DeprecatedUnstableVariant; //~ ERROR use of deprecated item
86         //~^ WARNING use of unstable library feature
87         let _ = Enum::UnstableVariant; //~ WARNING use of unstable library feature
88         let _ = Enum::StableVariant;
89
90         let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
91         let _ = DeprecatedUnstableTupleStruct (1); //~ ERROR use of deprecated item
92         //~^ WARNING use of unstable library feature
93         let _ = UnstableTupleStruct (1); //~ WARNING use of unstable library feature
94         let _ = StableTupleStruct (1);
95
96         // At the moment, the lint checker only checks stability in
97         // in the arguments of macros.
98         // Eventually, we will want to lint the contents of the
99         // macro in the module *defining* it. Also, stability levels
100         // on macros themselves are not yet linted.
101         macro_test_arg!(deprecated_text()); //~ ERROR use of deprecated item: text
102         macro_test_arg!(deprecated_unstable_text()); //~ ERROR use of deprecated item: text
103         //~^ WARNING use of unstable library feature
104         macro_test_arg!(macro_test_arg!(deprecated_text())); //~ ERROR use of deprecated item: text
105     }
106
107     fn test_method_param<F: Trait>(foo: F) {
108         foo.trait_deprecated(); //~ ERROR use of deprecated item
109         foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
110         foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item
111         //~^ WARNING use of unstable library feature
112         foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text
113         //~^ WARNING use of unstable library feature
114         foo.trait_unstable(); //~ WARNING use of unstable library feature
115         foo.trait_unstable_text(); //~ WARNING use of unstable library feature 'test_feature': text
116         foo.trait_stable();
117     }
118
119     fn test_method_object(foo: &Trait) {
120         foo.trait_deprecated(); //~ ERROR use of deprecated item
121         foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
122         foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item
123         //~^ WARNING use of unstable library feature
124         foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text
125         //~^ WARNING use of unstable library feature
126         foo.trait_unstable(); //~ WARNING use of unstable library feature
127         foo.trait_unstable_text(); //~ WARNING use of unstable library feature 'test_feature': text
128         foo.trait_stable();
129     }
130
131     struct S;
132
133     impl UnstableTrait for S { } //~ WARNING use of unstable library feature
134
135     trait LocalTrait : UnstableTrait { } //~ WARNING use of unstable library feature
136
137     impl Trait for S {
138         fn trait_stable(&self) {}
139         fn trait_unstable(&self) {} //~ WARNING use of unstable library feature
140     }
141 }
142
143 mod inheritance {
144     extern crate inherited_stability; //~ WARNING: use of unstable library feature
145     use self::inherited_stability::*; //~ WARNING: use of unstable library feature
146
147     fn test_inheritance() {
148         unstable(); //~ WARNING use of unstable library feature
149         stable();
150
151         stable_mod::unstable(); //~ WARNING use of unstable library feature
152         stable_mod::stable();
153
154         unstable_mod::deprecated(); //~ ERROR use of deprecated item
155         unstable_mod::unstable(); //~ WARNING use of unstable library feature
156
157         let _ = Unstable::UnstableVariant; //~ WARNING use of unstable library feature
158         let _ = Unstable::StableVariant;
159
160         let x: usize = 0;
161         x.unstable(); //~ WARNING use of unstable library feature
162         x.stable();
163     }
164 }
165
166 mod this_crate {
167     #[unstable(feature = "test_feature")]
168     #[deprecated(since = "1.0.0")]
169     pub fn deprecated() {}
170     #[unstable(feature = "test_feature")]
171     #[deprecated(since = "1.0.0", reason = "text")]
172     pub fn deprecated_text() {}
173
174     #[unstable(feature = "test_feature")]
175     pub fn unstable() {}
176     #[unstable(feature = "test_feature", reason = "text")]
177     pub fn unstable_text() {}
178
179     #[stable(feature = "rust1", since = "1.0.0")]
180     pub fn stable() {}
181     #[stable(feature = "rust1", since = "1.0.0", reason = "text")]
182     pub fn stable_text() {}
183
184     #[stable(feature = "rust1", since = "1.0.0")]
185     pub struct MethodTester;
186
187     impl MethodTester {
188         #[unstable(feature = "test_feature")]
189         #[deprecated(since = "1.0.0")]
190         pub fn method_deprecated(&self) {}
191         #[unstable(feature = "test_feature")]
192         #[deprecated(since = "1.0.0", reason = "text")]
193         pub fn method_deprecated_text(&self) {}
194
195         #[unstable(feature = "test_feature")]
196         pub fn method_unstable(&self) {}
197         #[unstable(feature = "test_feature", reason = "text")]
198         pub fn method_unstable_text(&self) {}
199
200         #[stable(feature = "rust1", since = "1.0.0")]
201         pub fn method_stable(&self) {}
202         #[stable(feature = "rust1", since = "1.0.0", reason = "text")]
203         pub fn method_stable_text(&self) {}
204     }
205
206     pub trait Trait {
207         #[unstable(feature = "test_feature")]
208         #[deprecated(since = "1.0.0")]
209         fn trait_deprecated(&self) {}
210         #[unstable(feature = "test_feature")]
211         #[deprecated(since = "1.0.0", reason = "text")]
212         fn trait_deprecated_text(&self) {}
213
214         #[unstable(feature = "test_feature")]
215         fn trait_unstable(&self) {}
216         #[unstable(feature = "test_feature", reason = "text")]
217         fn trait_unstable_text(&self) {}
218
219         #[stable(feature = "rust1", since = "1.0.0")]
220         fn trait_stable(&self) {}
221         #[stable(feature = "rust1", since = "1.0.0", reason = "text")]
222         fn trait_stable_text(&self) {}
223     }
224
225     impl Trait for MethodTester {}
226
227     #[unstable(feature = "test_feature")]
228     #[deprecated(since = "1.0.0")]
229     pub struct DeprecatedStruct { i: isize }
230     #[unstable(feature = "test_feature")]
231     pub struct UnstableStruct { i: isize }
232     #[stable(feature = "rust1", since = "1.0.0")]
233     pub struct StableStruct { i: isize }
234
235     #[unstable(feature = "test_feature")]
236     #[deprecated(since = "1.0.0")]
237     pub struct DeprecatedUnitStruct;
238     #[unstable(feature = "test_feature")]
239     pub struct UnstableUnitStruct;
240     #[stable(feature = "rust1", since = "1.0.0")]
241     pub struct StableUnitStruct;
242
243     pub enum Enum {
244         #[unstable(feature = "test_feature")]
245         #[deprecated(since = "1.0.0")]
246         DeprecatedVariant,
247         #[unstable(feature = "test_feature")]
248         UnstableVariant,
249
250         #[stable(feature = "rust1", since = "1.0.0")]
251         StableVariant,
252     }
253
254     #[unstable(feature = "test_feature")]
255     #[deprecated(since = "1.0.0")]
256     pub struct DeprecatedTupleStruct(isize);
257     #[unstable(feature = "test_feature")]
258     pub struct UnstableTupleStruct(isize);
259     #[stable(feature = "rust1", since = "1.0.0")]
260     pub struct StableTupleStruct(isize);
261
262     fn test() {
263         // Only the deprecated cases of the following should generate
264         // errors, because other stability attributes now have meaning
265         // only *across* crates, not within a single crate.
266
267         let foo = MethodTester;
268
269         deprecated(); //~ ERROR use of deprecated item
270         foo.method_deprecated(); //~ ERROR use of deprecated item
271         foo.trait_deprecated(); //~ ERROR use of deprecated item
272
273         deprecated_text(); //~ ERROR use of deprecated item: text
274         foo.method_deprecated_text(); //~ ERROR use of deprecated item: text
275         foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
276
277         unstable();
278         foo.method_unstable();
279         foo.trait_unstable();
280
281         unstable_text();
282         foo.method_unstable_text();
283         foo.trait_unstable_text();
284
285         stable();
286         foo.method_stable();
287         foo.trait_stable();
288
289         stable_text();
290         foo.method_stable_text();
291         foo.trait_stable_text();
292
293         let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
294         let _ = UnstableStruct { i: 0 };
295         let _ = StableStruct { i: 0 };
296
297         let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
298         let _ = UnstableUnitStruct;
299         let _ = StableUnitStruct;
300
301         let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item
302         let _ = Enum::UnstableVariant;
303         let _ = Enum::StableVariant;
304
305         let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
306         let _ = UnstableTupleStruct (1);
307         let _ = StableTupleStruct (1);
308     }
309
310     fn test_method_param<F: Trait>(foo: F) {
311         foo.trait_deprecated(); //~ ERROR use of deprecated item
312         foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
313         foo.trait_unstable();
314         foo.trait_unstable_text();
315         foo.trait_stable();
316     }
317
318     fn test_method_object(foo: &Trait) {
319         foo.trait_deprecated(); //~ ERROR use of deprecated item
320         foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
321         foo.trait_unstable();
322         foo.trait_unstable_text();
323         foo.trait_stable();
324     }
325
326     #[unstable(feature = "test_feature")]
327     #[deprecated(since = "1.0.0")]
328     fn test_fn_body() {
329         fn fn_in_body() {}
330         fn_in_body();
331     }
332
333     impl MethodTester {
334         #[unstable(feature = "test_feature")]
335         #[deprecated(since = "1.0.0")]
336         fn test_method_body(&self) {
337             fn fn_in_body() {}
338             fn_in_body();
339         }
340     }
341
342     #[unstable(feature = "test_feature")]
343     #[deprecated(since = "1.0.0")]
344     pub trait DeprecatedTrait {
345         fn dummy(&self) { }
346     }
347
348     struct S;
349
350     impl DeprecatedTrait for S { } //~ ERROR use of deprecated item
351
352     trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item
353 }
354
355 fn main() {}