1 // aux-build:lint_stability.rs
2 // aux-build:inherited_stability.rs
3 // aux-build:stability_cfg1.rs
4 // aux-build:stability-cfg2.rs
8 #![feature(staged_api)]
10 #![stable(feature = "rust1", since = "1.0.0")]
13 extern crate lint_stability;
16 extern crate stability_cfg1;
17 extern crate stability_cfg2; //~ ERROR use of unstable library feature
19 use lint_stability::*;
22 type Foo = MethodTester;
23 let foo = MethodTester;
26 foo.method_deprecated();
27 Foo::method_deprecated(&foo);
28 <Foo>::method_deprecated(&foo);
29 foo.trait_deprecated();
30 Trait::trait_deprecated(&foo);
31 <Foo>::trait_deprecated(&foo);
32 <Foo as Trait>::trait_deprecated(&foo);
35 foo.method_deprecated_text();
36 Foo::method_deprecated_text(&foo);
37 <Foo>::method_deprecated_text(&foo);
38 foo.trait_deprecated_text();
39 Trait::trait_deprecated_text(&foo);
40 <Foo>::trait_deprecated_text(&foo);
41 <Foo as Trait>::trait_deprecated_text(&foo);
43 deprecated_future(); // Fine; no error.
45 deprecated_unstable();
46 //~^ ERROR use of unstable library feature
47 Trait::trait_deprecated_unstable(&foo);
48 //~^ ERROR use of unstable library feature
49 <Foo as Trait>::trait_deprecated_unstable(&foo);
50 //~^ ERROR use of unstable library feature
52 deprecated_unstable_text();
53 //~^ ERROR use of unstable library feature
54 Trait::trait_deprecated_unstable_text(&foo);
55 //~^ ERROR use of unstable library feature
56 <Foo as Trait>::trait_deprecated_unstable_text(&foo);
57 //~^ ERROR use of unstable library feature
59 unstable(); //~ ERROR use of unstable library feature
60 Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature
61 <Foo as Trait>::trait_unstable(&foo); //~ ERROR use of unstable library feature
64 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
65 Trait::trait_unstable_text(&foo);
66 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
67 <Foo as Trait>::trait_unstable_text(&foo);
68 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
72 Foo::method_stable(&foo);
73 <Foo>::method_stable(&foo);
75 Trait::trait_stable(&foo);
76 <Foo>::trait_stable(&foo);
77 <Foo as Trait>::trait_stable(&foo);
80 foo.method_stable_text();
81 Foo::method_stable_text(&foo);
82 <Foo>::method_stable_text(&foo);
83 foo.trait_stable_text();
84 Trait::trait_stable_text(&foo);
85 <Foo>::trait_stable_text(&foo);
86 <Foo as Trait>::trait_stable_text(&foo);
88 struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
89 //~^ ERROR use of unstable library feature
90 struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
91 type A = dyn TraitWithAssociatedTypes<
92 TypeUnstable = u8, //~ ERROR use of unstable library feature
96 let _ = DeprecatedStruct {
99 let _ = DeprecatedUnstableStruct {
100 //~^ ERROR use of unstable library feature
103 let _ = UnstableStruct { i: 0 }; //~ ERROR use of unstable library feature
104 let _ = StableStruct { i: 0 };
106 let _ = DeprecatedUnitStruct;
107 let _ = DeprecatedUnstableUnitStruct;
108 //~^ ERROR use of unstable library feature
109 let _ = UnstableUnitStruct; //~ ERROR use of unstable library feature
110 let _ = StableUnitStruct;
112 let _ = Enum::DeprecatedVariant;
113 let _ = Enum::DeprecatedUnstableVariant;
114 //~^ ERROR use of unstable library feature
115 let _ = Enum::UnstableVariant; //~ ERROR use of unstable library feature
116 let _ = Enum::StableVariant;
118 let _ = DeprecatedTupleStruct (1);
119 let _ = DeprecatedUnstableTupleStruct (1);
120 //~^ ERROR use of unstable library feature
121 let _ = UnstableTupleStruct (1); //~ ERROR use of unstable library feature
122 let _ = StableTupleStruct (1);
124 // At the moment, the lint checker only checks stability in
125 // in the arguments of macros.
126 // Eventually, we will want to lint the contents of the
127 // macro in the module *defining* it. Also, stability levels
128 // on macros themselves are not yet linted.
129 macro_test_arg!(deprecated_text());
130 macro_test_arg!(deprecated_unstable_text());
131 //~^ ERROR use of unstable library feature
132 macro_test_arg!(macro_test_arg!(deprecated_text()));
135 fn test_method_param<Foo: Trait>(foo: Foo) {
136 foo.trait_deprecated();
137 Trait::trait_deprecated(&foo);
138 <Foo>::trait_deprecated(&foo);
139 <Foo as Trait>::trait_deprecated(&foo);
140 foo.trait_deprecated_text();
141 Trait::trait_deprecated_text(&foo);
142 <Foo>::trait_deprecated_text(&foo);
143 <Foo as Trait>::trait_deprecated_text(&foo);
144 Trait::trait_deprecated_unstable(&foo);
145 //~^ ERROR use of unstable library feature
146 <Foo as Trait>::trait_deprecated_unstable(&foo);
147 //~^ ERROR use of unstable library feature
148 Trait::trait_deprecated_unstable_text(&foo);
149 //~^ ERROR use of unstable library feature
150 <Foo as Trait>::trait_deprecated_unstable_text(&foo);
151 //~^ ERROR use of unstable library feature
152 Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature
153 <Foo as Trait>::trait_unstable(&foo); //~ ERROR use of unstable library feature
154 Trait::trait_unstable_text(&foo);
155 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
156 <Foo as Trait>::trait_unstable_text(&foo);
157 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
159 Trait::trait_stable(&foo);
160 <Foo>::trait_stable(&foo);
161 <Foo as Trait>::trait_stable(&foo);
164 fn test_method_object(foo: &dyn Trait) {
165 foo.trait_deprecated();
166 foo.trait_deprecated_text();
172 impl UnstableTrait for S { } //~ ERROR use of unstable library feature
173 impl DeprecatedTrait for S {}
174 trait LocalTrait : UnstableTrait { } //~ ERROR use of unstable library feature
175 trait LocalTrait2 : DeprecatedTrait { }
178 fn trait_stable(&self) {}
179 fn trait_unstable(&self) {} //~ ERROR use of unstable library feature
184 extern crate inherited_stability; //~ ERROR use of unstable library feature
185 use self::inherited_stability::*; //~ ERROR use of unstable library feature
187 fn test_inheritance() {
188 unstable(); //~ ERROR use of unstable library feature
191 stable_mod::unstable(); //~ ERROR use of unstable library feature
192 stable_mod::stable();
194 unstable_mod::deprecated(); //~ ERROR use of unstable library feature
195 unstable_mod::unstable(); //~ ERROR use of unstable library feature
197 let _ = Unstable::UnstableVariant; //~ ERROR use of unstable library feature
198 let _ = Unstable::StableVariant; //~ ERROR use of unstable library feature
206 #[unstable(feature = "unstable_test_feature", issue = "none")]
207 #[deprecated(since = "1.0.0", note = "text")]
208 pub fn deprecated() {}
209 #[unstable(feature = "unstable_test_feature", issue = "none")]
210 #[deprecated(since = "1.0.0", note = "text")]
211 pub fn deprecated_text() {}
213 #[stable(feature = "rust1", since = "1.0.0")]
214 #[deprecated(since = "99.99.99", note = "text")]
215 pub fn deprecated_future() {}
217 #[unstable(feature = "unstable_test_feature", issue = "none")]
219 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "none")]
220 pub fn unstable_text() {}
222 #[stable(feature = "rust1", since = "1.0.0")]
224 #[stable(feature = "rust1", since = "1.0.0")]
225 pub fn stable_text() {}
227 #[stable(feature = "rust1", since = "1.0.0")]
228 pub struct MethodTester;
231 #[unstable(feature = "unstable_test_feature", issue = "none")]
232 #[deprecated(since = "1.0.0", note = "text")]
233 pub fn method_deprecated(&self) {}
234 #[unstable(feature = "unstable_test_feature", issue = "none")]
235 #[deprecated(since = "1.0.0", note = "text")]
236 pub fn method_deprecated_text(&self) {}
238 #[unstable(feature = "unstable_test_feature", issue = "none")]
239 pub fn method_unstable(&self) {}
240 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "none")]
241 pub fn method_unstable_text(&self) {}
243 #[stable(feature = "rust1", since = "1.0.0")]
244 pub fn method_stable(&self) {}
245 #[stable(feature = "rust1", since = "1.0.0")]
246 pub fn method_stable_text(&self) {}
250 #[unstable(feature = "unstable_test_feature", issue = "none")]
251 #[deprecated(since = "1.0.0", note = "text")]
252 fn trait_deprecated(&self) {}
253 #[unstable(feature = "unstable_test_feature", issue = "none")]
254 #[deprecated(since = "1.0.0", note = "text")]
255 fn trait_deprecated_text(&self) {}
257 #[unstable(feature = "unstable_test_feature", issue = "none")]
258 fn trait_unstable(&self) {}
259 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "none")]
260 fn trait_unstable_text(&self) {}
262 #[stable(feature = "rust1", since = "1.0.0")]
263 fn trait_stable(&self) {}
264 #[stable(feature = "rust1", since = "1.0.0")]
265 fn trait_stable_text(&self) {}
268 impl Trait for MethodTester {}
270 #[unstable(feature = "unstable_test_feature", issue = "none")]
271 #[deprecated(since = "1.0.0", note = "text")]
272 pub struct DeprecatedStruct {
273 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
275 #[unstable(feature = "unstable_test_feature", issue = "none")]
276 pub struct UnstableStruct {
277 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
279 #[stable(feature = "rust1", since = "1.0.0")]
280 pub struct StableStruct {
281 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
284 #[unstable(feature = "unstable_test_feature", issue = "none")]
285 #[deprecated(since = "1.0.0", note = "text")]
286 pub struct DeprecatedUnitStruct;
287 #[unstable(feature = "unstable_test_feature", issue = "none")]
288 pub struct UnstableUnitStruct;
289 #[stable(feature = "rust1", since = "1.0.0")]
290 pub struct StableUnitStruct;
293 #[unstable(feature = "unstable_test_feature", issue = "none")]
294 #[deprecated(since = "1.0.0", note = "text")]
296 #[unstable(feature = "unstable_test_feature", issue = "none")]
299 #[stable(feature = "rust1", since = "1.0.0")]
303 #[unstable(feature = "unstable_test_feature", issue = "none")]
304 #[deprecated(since = "1.0.0", note = "text")]
305 pub struct DeprecatedTupleStruct(isize);
306 #[unstable(feature = "unstable_test_feature", issue = "none")]
307 pub struct UnstableTupleStruct(isize);
308 #[stable(feature = "rust1", since = "1.0.0")]
309 pub struct StableTupleStruct(isize);
312 // Only the deprecated cases of the following should generate
313 // errors, because other stability attributes now have meaning
314 // only *across* crates, not within a single crate.
316 type Foo = MethodTester;
317 let foo = MethodTester;
320 foo.method_deprecated();
321 Foo::method_deprecated(&foo);
322 <Foo>::method_deprecated(&foo);
323 foo.trait_deprecated();
324 Trait::trait_deprecated(&foo);
325 <Foo>::trait_deprecated(&foo);
326 <Foo as Trait>::trait_deprecated(&foo);
329 foo.method_deprecated_text();
330 Foo::method_deprecated_text(&foo);
331 <Foo>::method_deprecated_text(&foo);
332 foo.trait_deprecated_text();
333 Trait::trait_deprecated_text(&foo);
334 <Foo>::trait_deprecated_text(&foo);
335 <Foo as Trait>::trait_deprecated_text(&foo);
340 foo.method_unstable();
341 Foo::method_unstable(&foo);
342 <Foo>::method_unstable(&foo);
343 foo.trait_unstable();
344 Trait::trait_unstable(&foo);
345 <Foo>::trait_unstable(&foo);
346 <Foo as Trait>::trait_unstable(&foo);
349 foo.method_unstable_text();
350 Foo::method_unstable_text(&foo);
351 <Foo>::method_unstable_text(&foo);
352 foo.trait_unstable_text();
353 Trait::trait_unstable_text(&foo);
354 <Foo>::trait_unstable_text(&foo);
355 <Foo as Trait>::trait_unstable_text(&foo);
359 Foo::method_stable(&foo);
360 <Foo>::method_stable(&foo);
362 Trait::trait_stable(&foo);
363 <Foo>::trait_stable(&foo);
364 <Foo as Trait>::trait_stable(&foo);
367 foo.method_stable_text();
368 Foo::method_stable_text(&foo);
369 <Foo>::method_stable_text(&foo);
370 foo.trait_stable_text();
371 Trait::trait_stable_text(&foo);
372 <Foo>::trait_stable_text(&foo);
373 <Foo as Trait>::trait_stable_text(&foo);
375 let _ = DeprecatedStruct {
378 let _ = UnstableStruct { i: 0 };
379 let _ = StableStruct { i: 0 };
381 let _ = DeprecatedUnitStruct;
382 let _ = UnstableUnitStruct;
383 let _ = StableUnitStruct;
385 let _ = Enum::DeprecatedVariant;
386 let _ = Enum::UnstableVariant;
387 let _ = Enum::StableVariant;
389 let _ = DeprecatedTupleStruct (1);
390 let _ = UnstableTupleStruct (1);
391 let _ = StableTupleStruct (1);
394 fn test_method_param<Foo: Trait>(foo: Foo) {
395 foo.trait_deprecated();
396 Trait::trait_deprecated(&foo);
397 <Foo>::trait_deprecated(&foo);
398 <Foo as Trait>::trait_deprecated(&foo);
399 foo.trait_deprecated_text();
400 Trait::trait_deprecated_text(&foo);
401 <Foo>::trait_deprecated_text(&foo);
402 <Foo as Trait>::trait_deprecated_text(&foo);
403 foo.trait_unstable();
404 Trait::trait_unstable(&foo);
405 <Foo>::trait_unstable(&foo);
406 <Foo as Trait>::trait_unstable(&foo);
407 foo.trait_unstable_text();
408 Trait::trait_unstable_text(&foo);
409 <Foo>::trait_unstable_text(&foo);
410 <Foo as Trait>::trait_unstable_text(&foo);
412 Trait::trait_stable(&foo);
413 <Foo>::trait_stable(&foo);
414 <Foo as Trait>::trait_stable(&foo);
417 fn test_method_object(foo: &dyn Trait) {
418 foo.trait_deprecated();
419 foo.trait_deprecated_text();
420 foo.trait_unstable();
421 foo.trait_unstable_text();
425 #[unstable(feature = "unstable_test_feature", issue = "none")]
426 #[deprecated(since = "1.0.0", note = "text")]
433 #[unstable(feature = "unstable_test_feature", issue = "none")]
434 #[deprecated(since = "1.0.0", note = "text")]
435 fn test_method_body(&self) {
441 #[unstable(feature = "unstable_test_feature", issue = "none")]
442 #[deprecated(since = "1.0.0", note = "text")]
443 pub trait DeprecatedTrait {
449 impl DeprecatedTrait for S { }
451 trait LocalTrait : DeprecatedTrait { }