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
17 #![allow(dead_code, unused_extern_crates)]
18 #![feature(staged_api, test_feature, rustc_attrs)]
20 #![stable(feature = "rust1", since = "1.0.0")]
23 extern crate lint_stability;
26 extern crate stability_cfg1;
27 extern crate stability_cfg2;
29 use lint_stability::*;
32 type Foo = MethodTester;
33 let foo = MethodTester;
35 deprecated(); //~ WARN use of deprecated item
36 foo.method_deprecated(); //~ WARN use of deprecated item
37 Foo::method_deprecated(&foo); //~ WARN use of deprecated item
38 <Foo>::method_deprecated(&foo); //~ WARN use of deprecated item
39 foo.trait_deprecated(); //~ WARN use of deprecated item
40 Trait::trait_deprecated(&foo); //~ WARN use of deprecated item
41 <Foo>::trait_deprecated(&foo); //~ WARN use of deprecated item
42 <Foo as Trait>::trait_deprecated(&foo); //~ WARN use of deprecated item
44 deprecated_text(); //~ WARN use of deprecated item: text
45 foo.method_deprecated_text(); //~ WARN use of deprecated item: text
46 Foo::method_deprecated_text(&foo); //~ WARN use of deprecated item: text
47 <Foo>::method_deprecated_text(&foo); //~ WARN use of deprecated item: text
48 foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
49 Trait::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
50 <Foo>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
51 <Foo as Trait>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
53 deprecated_unstable(); //~ WARN use of deprecated item
54 foo.method_deprecated_unstable(); //~ WARN use of deprecated item
55 Foo::method_deprecated_unstable(&foo); //~ WARN use of deprecated item
56 <Foo>::method_deprecated_unstable(&foo); //~ WARN use of deprecated item
57 foo.trait_deprecated_unstable(); //~ WARN use of deprecated item
58 Trait::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
59 <Foo>::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
60 <Foo as Trait>::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
62 deprecated_unstable_text(); //~ WARN use of deprecated item: text
63 foo.method_deprecated_unstable_text(); //~ WARN use of deprecated item: text
64 Foo::method_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
65 <Foo>::method_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
66 foo.trait_deprecated_unstable_text(); //~ WARN use of deprecated item: text
67 Trait::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
68 <Foo>::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
69 <Foo as Trait>::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
72 foo.method_unstable();
73 Foo::method_unstable(&foo);
74 <Foo>::method_unstable(&foo);
76 Trait::trait_unstable(&foo);
77 <Foo>::trait_unstable(&foo);
78 <Foo as Trait>::trait_unstable(&foo);
81 foo.method_unstable_text();
82 Foo::method_unstable_text(&foo);
83 <Foo>::method_unstable_text(&foo);
84 foo.trait_unstable_text();
85 Trait::trait_unstable_text(&foo);
86 <Foo>::trait_unstable_text(&foo);
87 <Foo as Trait>::trait_unstable_text(&foo);
91 Foo::method_stable(&foo);
92 <Foo>::method_stable(&foo);
94 Trait::trait_stable(&foo);
95 <Foo>::trait_stable(&foo);
96 <Foo as Trait>::trait_stable(&foo);
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);
107 struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
108 struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
109 //~^ WARN use of deprecated item
111 let _ = DeprecatedStruct { //~ WARN use of deprecated item
112 i: 0 //~ WARN use of deprecated item
114 let _ = DeprecatedUnstableStruct {
115 //~^ WARN use of deprecated item
116 i: 0 //~ WARN use of deprecated item
118 let _ = UnstableStruct { i: 0 };
119 let _ = StableStruct { i: 0 };
121 let _ = DeprecatedUnitStruct; //~ WARN use of deprecated item
122 let _ = DeprecatedUnstableUnitStruct; //~ WARN use of deprecated item
123 let _ = UnstableUnitStruct;
124 let _ = StableUnitStruct;
126 let _ = Enum::DeprecatedVariant; //~ WARN use of deprecated item
127 let _ = Enum::DeprecatedUnstableVariant; //~ WARN use of deprecated item
128 let _ = Enum::UnstableVariant;
129 let _ = Enum::StableVariant;
131 let _ = DeprecatedTupleStruct (1); //~ WARN use of deprecated item
132 let _ = DeprecatedUnstableTupleStruct (1); //~ WARN use of deprecated item
133 let _ = UnstableTupleStruct (1);
134 let _ = StableTupleStruct (1);
136 // At the moment, the lint checker only checks stability in
137 // in the arguments of macros.
138 // Eventually, we will want to lint the contents of the
139 // macro in the module *defining* it. Also, stability levels
140 // on macros themselves are not yet linted.
141 macro_test_arg!(deprecated_text()); //~ WARN use of deprecated item: text
142 macro_test_arg!(deprecated_unstable_text()); //~ WARN use of deprecated item: text
143 macro_test_arg!(macro_test_arg!(deprecated_text())); //~ WARN use of deprecated item: text
146 fn test_method_param<Foo: Trait>(foo: Foo) {
147 foo.trait_deprecated(); //~ WARN use of deprecated item
148 Trait::trait_deprecated(&foo); //~ WARN use of deprecated item
149 <Foo>::trait_deprecated(&foo); //~ WARN use of deprecated item
150 <Foo as Trait>::trait_deprecated(&foo); //~ WARN use of deprecated item
151 foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
152 Trait::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
153 <Foo>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
154 <Foo as Trait>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
155 foo.trait_deprecated_unstable(); //~ WARN use of deprecated item
156 Trait::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
157 <Foo>::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
158 <Foo as Trait>::trait_deprecated_unstable(&foo); //~ WARN use of deprecated item
159 foo.trait_deprecated_unstable_text(); //~ WARN use of deprecated item: text
160 Trait::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
161 <Foo>::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
162 <Foo as Trait>::trait_deprecated_unstable_text(&foo); //~ WARN use of deprecated item: text
163 foo.trait_unstable();
164 Trait::trait_unstable(&foo);
165 <Foo>::trait_unstable(&foo);
166 <Foo as Trait>::trait_unstable(&foo);
167 foo.trait_unstable_text();
168 Trait::trait_unstable_text(&foo);
169 <Foo>::trait_unstable_text(&foo);
170 <Foo as Trait>::trait_unstable_text(&foo);
172 Trait::trait_stable(&foo);
173 <Foo>::trait_stable(&foo);
174 <Foo as Trait>::trait_stable(&foo);
177 fn test_method_object(foo: &Trait) {
178 foo.trait_deprecated(); //~ WARN use of deprecated item
179 foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
180 foo.trait_deprecated_unstable(); //~ WARN use of deprecated item
181 foo.trait_deprecated_unstable_text(); //~ WARN use of deprecated item: text
182 foo.trait_unstable();
183 foo.trait_unstable_text();
189 impl UnstableTrait for S { }
190 impl DeprecatedTrait for S {} //~ WARN use of deprecated item: text
191 trait LocalTrait : UnstableTrait { }
192 trait LocalTrait2 : DeprecatedTrait { } //~ WARN use of deprecated item: text
195 fn trait_stable(&self) {}
196 fn trait_unstable(&self) {}
201 extern crate inherited_stability;
202 use self::inherited_stability::*;
204 fn test_inheritance() {
208 stable_mod::unstable();
209 stable_mod::stable();
211 unstable_mod::deprecated(); //~ WARN use of deprecated item
212 unstable_mod::unstable();
214 let _ = Unstable::UnstableVariant;
215 let _ = Unstable::StableVariant;
224 #[unstable(feature = "test_feature", issue = "0")]
225 #[rustc_deprecated(since = "1.0.0", reason = "text")]
226 pub fn deprecated() {}
227 #[unstable(feature = "test_feature", issue = "0")]
228 #[rustc_deprecated(since = "1.0.0", reason = "text")]
229 pub fn deprecated_text() {}
231 #[unstable(feature = "test_feature", issue = "0")]
233 #[unstable(feature = "test_feature", reason = "text", issue = "0")]
234 pub fn unstable_text() {}
236 #[stable(feature = "rust1", since = "1.0.0")]
238 #[stable(feature = "rust1", since = "1.0.0")]
239 pub fn stable_text() {}
241 #[stable(feature = "rust1", since = "1.0.0")]
242 pub struct MethodTester;
245 #[unstable(feature = "test_feature", issue = "0")]
246 #[rustc_deprecated(since = "1.0.0", reason = "text")]
247 pub fn method_deprecated(&self) {}
248 #[unstable(feature = "test_feature", issue = "0")]
249 #[rustc_deprecated(since = "1.0.0", reason = "text")]
250 pub fn method_deprecated_text(&self) {}
252 #[unstable(feature = "test_feature", issue = "0")]
253 pub fn method_unstable(&self) {}
254 #[unstable(feature = "test_feature", reason = "text", issue = "0")]
255 pub fn method_unstable_text(&self) {}
257 #[stable(feature = "rust1", since = "1.0.0")]
258 pub fn method_stable(&self) {}
259 #[stable(feature = "rust1", since = "1.0.0")]
260 pub fn method_stable_text(&self) {}
264 #[unstable(feature = "test_feature", issue = "0")]
265 #[rustc_deprecated(since = "1.0.0", reason = "text")]
266 fn trait_deprecated(&self) {}
267 #[unstable(feature = "test_feature", issue = "0")]
268 #[rustc_deprecated(since = "1.0.0", reason = "text")]
269 fn trait_deprecated_text(&self) {}
271 #[unstable(feature = "test_feature", issue = "0")]
272 fn trait_unstable(&self) {}
273 #[unstable(feature = "test_feature", reason = "text", issue = "0")]
274 fn trait_unstable_text(&self) {}
276 #[stable(feature = "rust1", since = "1.0.0")]
277 fn trait_stable(&self) {}
278 #[stable(feature = "rust1", since = "1.0.0")]
279 fn trait_stable_text(&self) {}
282 impl Trait for MethodTester {}
284 #[unstable(feature = "test_feature", issue = "0")]
285 #[rustc_deprecated(since = "1.0.0", reason = "text")]
286 pub struct DeprecatedStruct {
287 #[stable(feature = "test_feature", since = "1.0.0")] i: isize
289 #[unstable(feature = "test_feature", issue = "0")]
290 pub struct UnstableStruct {
291 #[stable(feature = "test_feature", since = "1.0.0")] i: isize
293 #[stable(feature = "rust1", since = "1.0.0")]
294 pub struct StableStruct {
295 #[stable(feature = "test_feature", since = "1.0.0")] i: isize
298 #[unstable(feature = "test_feature", issue = "0")]
299 #[rustc_deprecated(since = "1.0.0", reason = "text")]
300 pub struct DeprecatedUnitStruct;
301 #[unstable(feature = "test_feature", issue = "0")]
302 pub struct UnstableUnitStruct;
303 #[stable(feature = "rust1", since = "1.0.0")]
304 pub struct StableUnitStruct;
307 #[unstable(feature = "test_feature", issue = "0")]
308 #[rustc_deprecated(since = "1.0.0", reason = "text")]
310 #[unstable(feature = "test_feature", issue = "0")]
313 #[stable(feature = "rust1", since = "1.0.0")]
317 #[unstable(feature = "test_feature", issue = "0")]
318 #[rustc_deprecated(since = "1.0.0", reason = "text")]
319 pub struct DeprecatedTupleStruct(isize);
320 #[unstable(feature = "test_feature", issue = "0")]
321 pub struct UnstableTupleStruct(isize);
322 #[stable(feature = "rust1", since = "1.0.0")]
323 pub struct StableTupleStruct(isize);
326 // Only the deprecated cases of the following should generate
327 // errors, because other stability attributes now have meaning
328 // only *across* crates, not within a single crate.
330 type Foo = MethodTester;
331 let foo = MethodTester;
333 deprecated(); //~ WARN use of deprecated item
334 foo.method_deprecated(); //~ WARN use of deprecated item
335 Foo::method_deprecated(&foo); //~ WARN use of deprecated item
336 <Foo>::method_deprecated(&foo); //~ WARN use of deprecated item
337 foo.trait_deprecated(); //~ WARN use of deprecated item
338 Trait::trait_deprecated(&foo); //~ WARN use of deprecated item
339 <Foo>::trait_deprecated(&foo); //~ WARN use of deprecated item
340 <Foo as Trait>::trait_deprecated(&foo); //~ WARN use of deprecated item
342 deprecated_text(); //~ WARN use of deprecated item: text
343 foo.method_deprecated_text(); //~ WARN use of deprecated item: text
344 Foo::method_deprecated_text(&foo); //~ WARN use of deprecated item: text
345 <Foo>::method_deprecated_text(&foo); //~ WARN use of deprecated item: text
346 foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
347 Trait::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
348 <Foo>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
349 <Foo as Trait>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
352 foo.method_unstable();
353 Foo::method_unstable(&foo);
354 <Foo>::method_unstable(&foo);
355 foo.trait_unstable();
356 Trait::trait_unstable(&foo);
357 <Foo>::trait_unstable(&foo);
358 <Foo as Trait>::trait_unstable(&foo);
361 foo.method_unstable_text();
362 Foo::method_unstable_text(&foo);
363 <Foo>::method_unstable_text(&foo);
364 foo.trait_unstable_text();
365 Trait::trait_unstable_text(&foo);
366 <Foo>::trait_unstable_text(&foo);
367 <Foo as Trait>::trait_unstable_text(&foo);
371 Foo::method_stable(&foo);
372 <Foo>::method_stable(&foo);
374 Trait::trait_stable(&foo);
375 <Foo>::trait_stable(&foo);
376 <Foo as Trait>::trait_stable(&foo);
379 foo.method_stable_text();
380 Foo::method_stable_text(&foo);
381 <Foo>::method_stable_text(&foo);
382 foo.trait_stable_text();
383 Trait::trait_stable_text(&foo);
384 <Foo>::trait_stable_text(&foo);
385 <Foo as Trait>::trait_stable_text(&foo);
387 let _ = DeprecatedStruct {
388 //~^ WARN use of deprecated item
389 i: 0 //~ WARN use of deprecated item
391 let _ = UnstableStruct { i: 0 };
392 let _ = StableStruct { i: 0 };
394 let _ = DeprecatedUnitStruct; //~ WARN use of deprecated item
395 let _ = UnstableUnitStruct;
396 let _ = StableUnitStruct;
398 let _ = Enum::DeprecatedVariant; //~ WARN use of deprecated item
399 let _ = Enum::UnstableVariant;
400 let _ = Enum::StableVariant;
402 let _ = DeprecatedTupleStruct (1); //~ WARN use of deprecated item
403 let _ = UnstableTupleStruct (1);
404 let _ = StableTupleStruct (1);
407 fn test_method_param<Foo: Trait>(foo: Foo) {
408 foo.trait_deprecated(); //~ WARN use of deprecated item
409 Trait::trait_deprecated(&foo); //~ WARN use of deprecated item
410 <Foo>::trait_deprecated(&foo); //~ WARN use of deprecated item
411 <Foo as Trait>::trait_deprecated(&foo); //~ WARN use of deprecated item
412 foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
413 Trait::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
414 <Foo>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
415 <Foo as Trait>::trait_deprecated_text(&foo); //~ WARN use of deprecated item: text
416 foo.trait_unstable();
417 Trait::trait_unstable(&foo);
418 <Foo>::trait_unstable(&foo);
419 <Foo as Trait>::trait_unstable(&foo);
420 foo.trait_unstable_text();
421 Trait::trait_unstable_text(&foo);
422 <Foo>::trait_unstable_text(&foo);
423 <Foo as Trait>::trait_unstable_text(&foo);
425 Trait::trait_stable(&foo);
426 <Foo>::trait_stable(&foo);
427 <Foo as Trait>::trait_stable(&foo);
430 fn test_method_object(foo: &Trait) {
431 foo.trait_deprecated(); //~ WARN use of deprecated item
432 foo.trait_deprecated_text(); //~ WARN use of deprecated item: text
433 foo.trait_unstable();
434 foo.trait_unstable_text();
438 #[unstable(feature = "test_feature", issue = "0")]
439 #[rustc_deprecated(since = "1.0.0", reason = "text")]
442 fn_in_body(); //~ WARN use of deprecated item: text
446 #[unstable(feature = "test_feature", issue = "0")]
447 #[rustc_deprecated(since = "1.0.0", reason = "text")]
448 fn test_method_body(&self) {
450 fn_in_body(); //~ WARN use of deprecated item: text
454 #[unstable(feature = "test_feature", issue = "0")]
455 #[rustc_deprecated(since = "1.0.0", reason = "text")]
456 pub trait DeprecatedTrait {
462 impl DeprecatedTrait for S { } //~ WARN use of deprecated item
464 trait LocalTrait : DeprecatedTrait { } //~ WARN use of deprecated item
467 #[rustc_error] fn main() {} //~ ERROR: compilation successful