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
18 #![feature(staged_api)]
20 #![stable(feature = "rust1", since = "1.0.0")]
23 extern crate lint_stability;
26 extern crate stability_cfg1;
27 extern crate stability_cfg2; //~ ERROR use of unstable library feature
29 use lint_stability::*;
32 type Foo = MethodTester;
33 let foo = MethodTester;
36 foo.method_deprecated();
37 Foo::method_deprecated(&foo);
38 <Foo>::method_deprecated(&foo);
39 foo.trait_deprecated();
40 Trait::trait_deprecated(&foo);
41 <Foo>::trait_deprecated(&foo);
42 <Foo as Trait>::trait_deprecated(&foo);
45 foo.method_deprecated_text();
46 Foo::method_deprecated_text(&foo);
47 <Foo>::method_deprecated_text(&foo);
48 foo.trait_deprecated_text();
49 Trait::trait_deprecated_text(&foo);
50 <Foo>::trait_deprecated_text(&foo);
51 <Foo as Trait>::trait_deprecated_text(&foo);
53 deprecated_future(); // Fine; no error.
55 deprecated_unstable();
56 //~^ ERROR use of unstable library feature
57 Trait::trait_deprecated_unstable(&foo);
58 //~^ ERROR use of unstable library feature
59 <Foo as Trait>::trait_deprecated_unstable(&foo);
60 //~^ ERROR use of unstable library feature
62 deprecated_unstable_text();
63 //~^ ERROR use of unstable library feature
64 Trait::trait_deprecated_unstable_text(&foo);
65 //~^ ERROR use of unstable library feature
66 <Foo as Trait>::trait_deprecated_unstable_text(&foo);
67 //~^ ERROR use of unstable library feature
69 unstable(); //~ ERROR use of unstable library feature
70 Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature
71 <Foo as Trait>::trait_unstable(&foo); //~ ERROR use of unstable library feature
74 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
75 Trait::trait_unstable_text(&foo);
76 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
77 <Foo as Trait>::trait_unstable_text(&foo);
78 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
82 Foo::method_stable(&foo);
83 <Foo>::method_stable(&foo);
85 Trait::trait_stable(&foo);
86 <Foo>::trait_stable(&foo);
87 <Foo as Trait>::trait_stable(&foo);
90 foo.method_stable_text();
91 Foo::method_stable_text(&foo);
92 <Foo>::method_stable_text(&foo);
93 foo.trait_stable_text();
94 Trait::trait_stable_text(&foo);
95 <Foo>::trait_stable_text(&foo);
96 <Foo as Trait>::trait_stable_text(&foo);
98 struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
99 //~^ ERROR use of unstable library feature
100 struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
101 type A = TraitWithAssociatedTypes<
102 TypeUnstable = u8, //~ ERROR use of unstable library feature
103 TypeDeprecated = u16,
106 let _ = DeprecatedStruct {
109 let _ = DeprecatedUnstableStruct {
110 //~^ ERROR use of unstable library feature
113 let _ = UnstableStruct { i: 0 }; //~ ERROR use of unstable library feature
114 let _ = StableStruct { i: 0 };
116 let _ = DeprecatedUnitStruct;
117 let _ = DeprecatedUnstableUnitStruct;
118 //~^ ERROR use of unstable library feature
119 let _ = UnstableUnitStruct; //~ ERROR use of unstable library feature
120 let _ = StableUnitStruct;
122 let _ = Enum::DeprecatedVariant;
123 let _ = Enum::DeprecatedUnstableVariant;
124 //~^ ERROR use of unstable library feature
125 let _ = Enum::UnstableVariant; //~ ERROR use of unstable library feature
126 let _ = Enum::StableVariant;
128 let _ = DeprecatedTupleStruct (1);
129 let _ = DeprecatedUnstableTupleStruct (1);
130 //~^ ERROR use of unstable library feature
131 let _ = UnstableTupleStruct (1); //~ ERROR use of unstable library feature
132 let _ = StableTupleStruct (1);
134 // At the moment, the lint checker only checks stability in
135 // in the arguments of macros.
136 // Eventually, we will want to lint the contents of the
137 // macro in the module *defining* it. Also, stability levels
138 // on macros themselves are not yet linted.
139 macro_test_arg!(deprecated_text());
140 macro_test_arg!(deprecated_unstable_text());
141 //~^ ERROR use of unstable library feature
142 macro_test_arg!(macro_test_arg!(deprecated_text()));
145 fn test_method_param<Foo: Trait>(foo: Foo) {
146 foo.trait_deprecated();
147 Trait::trait_deprecated(&foo);
148 <Foo>::trait_deprecated(&foo);
149 <Foo as Trait>::trait_deprecated(&foo);
150 foo.trait_deprecated_text();
151 Trait::trait_deprecated_text(&foo);
152 <Foo>::trait_deprecated_text(&foo);
153 <Foo as Trait>::trait_deprecated_text(&foo);
154 Trait::trait_deprecated_unstable(&foo);
155 //~^ ERROR use of unstable library feature
156 <Foo as Trait>::trait_deprecated_unstable(&foo);
157 //~^ ERROR use of unstable library feature
158 Trait::trait_deprecated_unstable_text(&foo);
159 //~^ ERROR use of unstable library feature
160 <Foo as Trait>::trait_deprecated_unstable_text(&foo);
161 //~^ ERROR use of unstable library feature
162 Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature
163 <Foo as Trait>::trait_unstable(&foo); //~ ERROR use of unstable library feature
164 Trait::trait_unstable_text(&foo);
165 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
166 <Foo as Trait>::trait_unstable_text(&foo);
167 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
169 Trait::trait_stable(&foo);
170 <Foo>::trait_stable(&foo);
171 <Foo as Trait>::trait_stable(&foo);
174 fn test_method_object(foo: &Trait) {
175 foo.trait_deprecated();
176 foo.trait_deprecated_text();
182 impl UnstableTrait for S { } //~ ERROR use of unstable library feature
183 impl DeprecatedTrait for S {}
184 trait LocalTrait : UnstableTrait { } //~ ERROR use of unstable library feature
185 trait LocalTrait2 : DeprecatedTrait { }
188 fn trait_stable(&self) {}
189 fn trait_unstable(&self) {} //~ ERROR use of unstable library feature
194 extern crate inherited_stability; //~ ERROR use of unstable library feature
195 use self::inherited_stability::*; //~ ERROR use of unstable library feature
197 fn test_inheritance() {
198 unstable(); //~ ERROR use of unstable library feature
201 stable_mod::unstable(); //~ ERROR use of unstable library feature
202 stable_mod::stable();
204 unstable_mod::deprecated();
205 unstable_mod::unstable(); //~ ERROR use of unstable library feature
207 let _ = Unstable::UnstableVariant; //~ ERROR use of unstable library feature
208 let _ = Unstable::StableVariant;
216 #[unstable(feature = "unstable_test_feature", issue = "0")]
217 #[rustc_deprecated(since = "1.0.0", reason = "text")]
218 pub fn deprecated() {}
219 #[unstable(feature = "unstable_test_feature", issue = "0")]
220 #[rustc_deprecated(since = "1.0.0", reason = "text")]
221 pub fn deprecated_text() {}
223 #[stable(feature = "rust1", since = "1.0.0")]
224 #[rustc_deprecated(since = "99.99.99", reason = "text")]
225 pub fn deprecated_future() {}
227 #[unstable(feature = "unstable_test_feature", issue = "0")]
229 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "0")]
230 pub fn unstable_text() {}
232 #[stable(feature = "rust1", since = "1.0.0")]
234 #[stable(feature = "rust1", since = "1.0.0")]
235 pub fn stable_text() {}
237 #[stable(feature = "rust1", since = "1.0.0")]
238 pub struct MethodTester;
241 #[unstable(feature = "unstable_test_feature", issue = "0")]
242 #[rustc_deprecated(since = "1.0.0", reason = "text")]
243 pub fn method_deprecated(&self) {}
244 #[unstable(feature = "unstable_test_feature", issue = "0")]
245 #[rustc_deprecated(since = "1.0.0", reason = "text")]
246 pub fn method_deprecated_text(&self) {}
248 #[unstable(feature = "unstable_test_feature", issue = "0")]
249 pub fn method_unstable(&self) {}
250 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "0")]
251 pub fn method_unstable_text(&self) {}
253 #[stable(feature = "rust1", since = "1.0.0")]
254 pub fn method_stable(&self) {}
255 #[stable(feature = "rust1", since = "1.0.0")]
256 pub fn method_stable_text(&self) {}
260 #[unstable(feature = "unstable_test_feature", issue = "0")]
261 #[rustc_deprecated(since = "1.0.0", reason = "text")]
262 fn trait_deprecated(&self) {}
263 #[unstable(feature = "unstable_test_feature", issue = "0")]
264 #[rustc_deprecated(since = "1.0.0", reason = "text")]
265 fn trait_deprecated_text(&self) {}
267 #[unstable(feature = "unstable_test_feature", issue = "0")]
268 fn trait_unstable(&self) {}
269 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "0")]
270 fn trait_unstable_text(&self) {}
272 #[stable(feature = "rust1", since = "1.0.0")]
273 fn trait_stable(&self) {}
274 #[stable(feature = "rust1", since = "1.0.0")]
275 fn trait_stable_text(&self) {}
278 impl Trait for MethodTester {}
280 #[unstable(feature = "unstable_test_feature", issue = "0")]
281 #[rustc_deprecated(since = "1.0.0", reason = "text")]
282 pub struct DeprecatedStruct {
283 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
285 #[unstable(feature = "unstable_test_feature", issue = "0")]
286 pub struct UnstableStruct {
287 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
289 #[stable(feature = "rust1", since = "1.0.0")]
290 pub struct StableStruct {
291 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
294 #[unstable(feature = "unstable_test_feature", issue = "0")]
295 #[rustc_deprecated(since = "1.0.0", reason = "text")]
296 pub struct DeprecatedUnitStruct;
297 #[unstable(feature = "unstable_test_feature", issue = "0")]
298 pub struct UnstableUnitStruct;
299 #[stable(feature = "rust1", since = "1.0.0")]
300 pub struct StableUnitStruct;
303 #[unstable(feature = "unstable_test_feature", issue = "0")]
304 #[rustc_deprecated(since = "1.0.0", reason = "text")]
306 #[unstable(feature = "unstable_test_feature", issue = "0")]
309 #[stable(feature = "rust1", since = "1.0.0")]
313 #[unstable(feature = "unstable_test_feature", issue = "0")]
314 #[rustc_deprecated(since = "1.0.0", reason = "text")]
315 pub struct DeprecatedTupleStruct(isize);
316 #[unstable(feature = "unstable_test_feature", issue = "0")]
317 pub struct UnstableTupleStruct(isize);
318 #[stable(feature = "rust1", since = "1.0.0")]
319 pub struct StableTupleStruct(isize);
322 // Only the deprecated cases of the following should generate
323 // errors, because other stability attributes now have meaning
324 // only *across* crates, not within a single crate.
326 type Foo = MethodTester;
327 let foo = MethodTester;
330 foo.method_deprecated();
331 Foo::method_deprecated(&foo);
332 <Foo>::method_deprecated(&foo);
333 foo.trait_deprecated();
334 Trait::trait_deprecated(&foo);
335 <Foo>::trait_deprecated(&foo);
336 <Foo as Trait>::trait_deprecated(&foo);
339 foo.method_deprecated_text();
340 Foo::method_deprecated_text(&foo);
341 <Foo>::method_deprecated_text(&foo);
342 foo.trait_deprecated_text();
343 Trait::trait_deprecated_text(&foo);
344 <Foo>::trait_deprecated_text(&foo);
345 <Foo as Trait>::trait_deprecated_text(&foo);
350 foo.method_unstable();
351 Foo::method_unstable(&foo);
352 <Foo>::method_unstable(&foo);
353 foo.trait_unstable();
354 Trait::trait_unstable(&foo);
355 <Foo>::trait_unstable(&foo);
356 <Foo as Trait>::trait_unstable(&foo);
359 foo.method_unstable_text();
360 Foo::method_unstable_text(&foo);
361 <Foo>::method_unstable_text(&foo);
362 foo.trait_unstable_text();
363 Trait::trait_unstable_text(&foo);
364 <Foo>::trait_unstable_text(&foo);
365 <Foo as Trait>::trait_unstable_text(&foo);
369 Foo::method_stable(&foo);
370 <Foo>::method_stable(&foo);
372 Trait::trait_stable(&foo);
373 <Foo>::trait_stable(&foo);
374 <Foo as Trait>::trait_stable(&foo);
377 foo.method_stable_text();
378 Foo::method_stable_text(&foo);
379 <Foo>::method_stable_text(&foo);
380 foo.trait_stable_text();
381 Trait::trait_stable_text(&foo);
382 <Foo>::trait_stable_text(&foo);
383 <Foo as Trait>::trait_stable_text(&foo);
385 let _ = DeprecatedStruct {
388 let _ = UnstableStruct { i: 0 };
389 let _ = StableStruct { i: 0 };
391 let _ = DeprecatedUnitStruct;
392 let _ = UnstableUnitStruct;
393 let _ = StableUnitStruct;
395 let _ = Enum::DeprecatedVariant;
396 let _ = Enum::UnstableVariant;
397 let _ = Enum::StableVariant;
399 let _ = DeprecatedTupleStruct (1);
400 let _ = UnstableTupleStruct (1);
401 let _ = StableTupleStruct (1);
404 fn test_method_param<Foo: Trait>(foo: Foo) {
405 foo.trait_deprecated();
406 Trait::trait_deprecated(&foo);
407 <Foo>::trait_deprecated(&foo);
408 <Foo as Trait>::trait_deprecated(&foo);
409 foo.trait_deprecated_text();
410 Trait::trait_deprecated_text(&foo);
411 <Foo>::trait_deprecated_text(&foo);
412 <Foo as Trait>::trait_deprecated_text(&foo);
413 foo.trait_unstable();
414 Trait::trait_unstable(&foo);
415 <Foo>::trait_unstable(&foo);
416 <Foo as Trait>::trait_unstable(&foo);
417 foo.trait_unstable_text();
418 Trait::trait_unstable_text(&foo);
419 <Foo>::trait_unstable_text(&foo);
420 <Foo as Trait>::trait_unstable_text(&foo);
422 Trait::trait_stable(&foo);
423 <Foo>::trait_stable(&foo);
424 <Foo as Trait>::trait_stable(&foo);
427 fn test_method_object(foo: &Trait) {
428 foo.trait_deprecated();
429 foo.trait_deprecated_text();
430 foo.trait_unstable();
431 foo.trait_unstable_text();
435 #[unstable(feature = "unstable_test_feature", issue = "0")]
436 #[rustc_deprecated(since = "1.0.0", reason = "text")]
443 #[unstable(feature = "unstable_test_feature", issue = "0")]
444 #[rustc_deprecated(since = "1.0.0", reason = "text")]
445 fn test_method_body(&self) {
451 #[unstable(feature = "unstable_test_feature", issue = "0")]
452 #[rustc_deprecated(since = "1.0.0", reason = "text")]
453 pub trait DeprecatedTrait {
459 impl DeprecatedTrait for S { }
461 trait LocalTrait : DeprecatedTrait { }