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.
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.
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
19 #![feature(staged_api)]
23 extern crate lint_stability;
26 extern crate stability_cfg1;
27 extern crate stability_cfg2; //~ WARNING: use of unstable library feature
29 use lint_stability::*;
32 let foo = MethodTester;
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
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
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
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
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
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
69 foo.method_stable_text();
70 foo.trait_stable_text();
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 };
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;
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;
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);
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
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
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
133 impl UnstableTrait for S { } //~ WARNING use of unstable library feature
135 trait LocalTrait : UnstableTrait { } //~ WARNING use of unstable library feature
138 fn trait_stable(&self) {}
139 fn trait_unstable(&self) {} //~ WARNING use of unstable library feature
144 extern crate inherited_stability; //~ WARNING: use of unstable library feature
145 use self::inherited_stability::*; //~ WARNING: use of unstable library feature
147 fn test_inheritance() {
148 unstable(); //~ WARNING use of unstable library feature
151 stable_mod::unstable(); //~ WARNING use of unstable library feature
152 stable_mod::stable();
154 unstable_mod::deprecated(); //~ ERROR use of deprecated item
155 unstable_mod::unstable(); //~ WARNING use of unstable library feature
157 let _ = Unstable::UnstableVariant; //~ WARNING use of unstable library feature
158 let _ = Unstable::StableVariant;
161 x.unstable(); //~ WARNING use of unstable library feature
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() {}
174 #[unstable(feature = "test_feature")]
176 #[unstable(feature = "test_feature", reason = "text")]
177 pub fn unstable_text() {}
179 #[stable(feature = "rust1", since = "1.0.0")]
181 #[stable(feature = "rust1", since = "1.0.0", reason = "text")]
182 pub fn stable_text() {}
184 #[stable(feature = "rust1", since = "1.0.0")]
185 pub struct 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) {}
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) {}
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) {}
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) {}
214 #[unstable(feature = "test_feature")]
215 fn trait_unstable(&self) {}
216 #[unstable(feature = "test_feature", reason = "text")]
217 fn trait_unstable_text(&self) {}
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) {}
225 impl Trait for MethodTester {}
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 }
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;
244 #[unstable(feature = "test_feature")]
245 #[deprecated(since = "1.0.0")]
247 #[unstable(feature = "test_feature")]
250 #[stable(feature = "rust1", since = "1.0.0")]
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);
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.
267 let foo = MethodTester;
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
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
278 foo.method_unstable();
279 foo.trait_unstable();
282 foo.method_unstable_text();
283 foo.trait_unstable_text();
290 foo.method_stable_text();
291 foo.trait_stable_text();
293 let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
294 let _ = UnstableStruct { i: 0 };
295 let _ = StableStruct { i: 0 };
297 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
298 let _ = UnstableUnitStruct;
299 let _ = StableUnitStruct;
301 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item
302 let _ = Enum::UnstableVariant;
303 let _ = Enum::StableVariant;
305 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
306 let _ = UnstableTupleStruct (1);
307 let _ = StableTupleStruct (1);
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();
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();
326 #[unstable(feature = "test_feature")]
327 #[deprecated(since = "1.0.0")]
334 #[unstable(feature = "test_feature")]
335 #[deprecated(since = "1.0.0")]
336 fn test_method_body(&self) {
342 #[unstable(feature = "test_feature")]
343 #[deprecated(since = "1.0.0")]
344 pub trait DeprecatedTrait {}
348 impl DeprecatedTrait for S { } //~ ERROR use of deprecated item
350 trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item