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:stability_cfg1.rs
16 #![feature(staged_api)]
18 #![stable(feature = "rust1", since = "1.0.0")]
21 extern crate lint_stability;
24 extern crate stability_cfg1;
26 use lint_stability::*;
29 type Foo = MethodTester;
30 let foo = MethodTester;
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);
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);
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
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
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
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
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 S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
109 let _ = DeprecatedStruct {
112 let _ = StableStruct { i: 0 };
114 let _ = DeprecatedUnitStruct;
115 let _ = StableUnitStruct;
117 let _ = Enum::DeprecatedVariant;
118 let _ = Enum::StableVariant;
120 let _ = DeprecatedTupleStruct (1);
121 let _ = StableTupleStruct (1);
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()));
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
156 Trait::trait_stable(&foo);
157 <Foo>::trait_stable(&foo);
158 <Foo as Trait>::trait_stable(&foo);
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
176 impl DeprecatedTrait for S {}
177 trait LocalTrait2 : DeprecatedTrait { }
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() {}
188 #[unstable(feature = "unstable_test_feature", issue = "0")]
190 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "0")]
191 pub fn unstable_text() {}
193 #[stable(feature = "rust1", since = "1.0.0")]
195 #[stable(feature = "rust1", since = "1.0.0")]
196 pub fn stable_text() {}
198 #[stable(feature = "rust1", since = "1.0.0")]
199 pub struct 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) {}
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) {}
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) {}
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) {}
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) {}
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) {}
239 impl Trait for MethodTester {}
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
246 #[unstable(feature = "unstable_test_feature", issue = "0")]
247 pub struct UnstableStruct {
248 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
250 #[stable(feature = "rust1", since = "1.0.0")]
251 pub struct StableStruct {
252 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
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;
264 #[unstable(feature = "unstable_test_feature", issue = "0")]
265 #[rustc_deprecated(since = "1.0.0", reason = "text")]
267 #[unstable(feature = "unstable_test_feature", issue = "0")]
270 #[stable(feature = "rust1", since = "1.0.0")]
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);
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.
287 type Foo = MethodTester;
288 let foo = MethodTester;
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);
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);
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);
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);
328 Foo::method_stable(&foo);
329 <Foo>::method_stable(&foo);
331 Trait::trait_stable(&foo);
332 <Foo>::trait_stable(&foo);
333 <Foo as Trait>::trait_stable(&foo);
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);
344 let _ = DeprecatedStruct {
347 let _ = UnstableStruct { i: 0 };
348 let _ = StableStruct { i: 0 };
350 let _ = DeprecatedUnitStruct;
351 let _ = UnstableUnitStruct;
352 let _ = StableUnitStruct;
354 let _ = Enum::DeprecatedVariant;
355 let _ = Enum::UnstableVariant;
356 let _ = Enum::StableVariant;
358 let _ = DeprecatedTupleStruct (1);
359 let _ = UnstableTupleStruct (1);
360 let _ = StableTupleStruct (1);
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);
381 Trait::trait_stable(&foo);
382 <Foo>::trait_stable(&foo);
383 <Foo as Trait>::trait_stable(&foo);
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();
394 #[unstable(feature = "unstable_test_feature", issue = "0")]
395 #[rustc_deprecated(since = "1.0.0", reason = "text")]
402 #[unstable(feature = "unstable_test_feature", issue = "0")]
403 #[rustc_deprecated(since = "1.0.0", reason = "text")]
404 fn test_method_body(&self) {
410 #[unstable(feature = "unstable_test_feature", issue = "0")]
411 #[rustc_deprecated(since = "1.0.0", reason = "text")]
412 pub trait DeprecatedTrait {
418 impl DeprecatedTrait for S { }
420 trait LocalTrait : DeprecatedTrait { }