1 // aux-build:lint_stability.rs
2 // aux-build:stability_cfg1.rs
6 #![feature(staged_api)]
8 #![stable(feature = "rust1", since = "1.0.0")]
11 extern crate lint_stability;
14 extern crate stability_cfg1;
16 use lint_stability::*;
19 type Foo = MethodTester;
20 let foo = MethodTester;
23 foo.method_deprecated();
24 Foo::method_deprecated(&foo);
25 <Foo>::method_deprecated(&foo);
26 foo.trait_deprecated();
27 Trait::trait_deprecated(&foo);
28 <Foo>::trait_deprecated(&foo);
29 <Foo as Trait>::trait_deprecated(&foo);
32 foo.method_deprecated_text();
33 Foo::method_deprecated_text(&foo);
34 <Foo>::method_deprecated_text(&foo);
35 foo.trait_deprecated_text();
36 Trait::trait_deprecated_text(&foo);
37 <Foo>::trait_deprecated_text(&foo);
38 <Foo as Trait>::trait_deprecated_text(&foo);
40 foo.method_deprecated_unstable();
41 //~^ ERROR use of unstable library feature
42 Foo::method_deprecated_unstable(&foo);
43 //~^ ERROR use of unstable library feature
44 <Foo>::method_deprecated_unstable(&foo);
45 //~^ ERROR use of unstable library feature
46 foo.trait_deprecated_unstable();
47 //~^ ERROR use of unstable library feature
48 <Foo>::trait_deprecated_unstable(&foo);
49 //~^ ERROR use of unstable library feature
51 foo.method_deprecated_unstable_text();
52 //~^ ERROR use of unstable library feature
53 Foo::method_deprecated_unstable_text(&foo);
54 //~^ ERROR use of unstable library feature
55 <Foo>::method_deprecated_unstable_text(&foo);
56 //~^ ERROR use of unstable library feature
57 foo.trait_deprecated_unstable_text();
58 //~^ ERROR use of unstable library feature
59 <Foo>::trait_deprecated_unstable_text(&foo);
60 //~^ ERROR use of unstable library feature
62 foo.method_unstable(); //~ ERROR use of unstable library feature
63 Foo::method_unstable(&foo); //~ ERROR use of unstable library feature
64 <Foo>::method_unstable(&foo); //~ ERROR use of unstable library feature
65 foo.trait_unstable(); //~ ERROR use of unstable library feature
66 <Foo>::trait_unstable(&foo); //~ ERROR use of unstable library feature
68 foo.method_unstable_text();
69 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
70 Foo::method_unstable_text(&foo);
71 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
72 <Foo>::method_unstable_text(&foo);
73 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
74 foo.trait_unstable_text();
75 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
76 <Foo>::trait_unstable_text(&foo);
77 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
81 Foo::method_stable(&foo);
82 <Foo>::method_stable(&foo);
84 Trait::trait_stable(&foo);
85 <Foo>::trait_stable(&foo);
86 <Foo as Trait>::trait_stable(&foo);
89 foo.method_stable_text();
90 Foo::method_stable_text(&foo);
91 <Foo>::method_stable_text(&foo);
92 foo.trait_stable_text();
93 Trait::trait_stable_text(&foo);
94 <Foo>::trait_stable_text(&foo);
95 <Foo as Trait>::trait_stable_text(&foo);
97 struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
99 let _ = DeprecatedStruct {
102 let _ = StableStruct { i: 0 };
104 let _ = DeprecatedUnitStruct;
105 let _ = StableUnitStruct;
107 let _ = Enum::DeprecatedVariant;
108 let _ = Enum::StableVariant;
110 let _ = DeprecatedTupleStruct (1);
111 let _ = StableTupleStruct (1);
113 // At the moment, the lint checker only checks stability in
114 // in the arguments of macros.
115 // Eventually, we will want to lint the contents of the
116 // macro in the module *defining* it. Also, stability levels
117 // on macros themselves are not yet linted.
118 macro_test_arg!(deprecated_text());
119 macro_test_arg!(macro_test_arg!(deprecated_text()));
122 fn test_method_param<Foo: Trait>(foo: Foo) {
123 foo.trait_deprecated();
124 Trait::trait_deprecated(&foo);
125 <Foo>::trait_deprecated(&foo);
126 <Foo as Trait>::trait_deprecated(&foo);
127 foo.trait_deprecated_text();
128 Trait::trait_deprecated_text(&foo);
129 <Foo>::trait_deprecated_text(&foo);
130 <Foo as Trait>::trait_deprecated_text(&foo);
131 foo.trait_deprecated_unstable();
132 //~^ ERROR use of unstable library feature
133 <Foo>::trait_deprecated_unstable(&foo);
134 //~^ ERROR use of unstable library feature
135 foo.trait_deprecated_unstable_text();
136 //~^ ERROR use of unstable library feature
137 <Foo>::trait_deprecated_unstable_text(&foo);
138 //~^ ERROR use of unstable library feature
139 foo.trait_unstable(); //~ ERROR use of unstable library feature
140 <Foo>::trait_unstable(&foo); //~ ERROR use of unstable library feature
141 foo.trait_unstable_text();
142 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
143 <Foo>::trait_unstable_text(&foo);
144 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
146 Trait::trait_stable(&foo);
147 <Foo>::trait_stable(&foo);
148 <Foo as Trait>::trait_stable(&foo);
151 fn test_method_object(foo: &dyn Trait) {
152 foo.trait_deprecated();
153 foo.trait_deprecated_text();
154 foo.trait_deprecated_unstable();
155 //~^ ERROR use of unstable library feature
156 foo.trait_deprecated_unstable_text();
157 //~^ ERROR use of unstable library feature
158 foo.trait_unstable(); //~ ERROR use of unstable library feature
159 foo.trait_unstable_text();
160 //~^ ERROR use of unstable library feature 'unstable_test_feature': text
166 impl DeprecatedTrait for S {}
167 trait LocalTrait2 : DeprecatedTrait { }
171 #[unstable(feature = "unstable_test_feature", issue = "none")]
172 #[rustc_deprecated(since = "1.0.0", reason = "text")]
173 pub fn deprecated() {}
174 #[unstable(feature = "unstable_test_feature", issue = "none")]
175 #[rustc_deprecated(since = "1.0.0", reason = "text")]
176 pub fn deprecated_text() {}
178 #[unstable(feature = "unstable_test_feature", issue = "none")]
180 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "none")]
181 pub fn unstable_text() {}
183 #[stable(feature = "rust1", since = "1.0.0")]
185 #[stable(feature = "rust1", since = "1.0.0")]
186 pub fn stable_text() {}
188 #[stable(feature = "rust1", since = "1.0.0")]
189 pub struct MethodTester;
192 #[unstable(feature = "unstable_test_feature", issue = "none")]
193 #[rustc_deprecated(since = "1.0.0", reason = "text")]
194 pub fn method_deprecated(&self) {}
195 #[unstable(feature = "unstable_test_feature", issue = "none")]
196 #[rustc_deprecated(since = "1.0.0", reason = "text")]
197 pub fn method_deprecated_text(&self) {}
199 #[unstable(feature = "unstable_test_feature", issue = "none")]
200 pub fn method_unstable(&self) {}
201 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "none")]
202 pub fn method_unstable_text(&self) {}
204 #[stable(feature = "rust1", since = "1.0.0")]
205 pub fn method_stable(&self) {}
206 #[stable(feature = "rust1", since = "1.0.0")]
207 pub fn method_stable_text(&self) {}
211 #[unstable(feature = "unstable_test_feature", issue = "none")]
212 #[rustc_deprecated(since = "1.0.0", reason = "text")]
213 fn trait_deprecated(&self) {}
214 #[unstable(feature = "unstable_test_feature", issue = "none")]
215 #[rustc_deprecated(since = "1.0.0", reason = "text")]
216 fn trait_deprecated_text(&self) {}
218 #[unstable(feature = "unstable_test_feature", issue = "none")]
219 fn trait_unstable(&self) {}
220 #[unstable(feature = "unstable_test_feature", reason = "text", issue = "none")]
221 fn trait_unstable_text(&self) {}
223 #[stable(feature = "rust1", since = "1.0.0")]
224 fn trait_stable(&self) {}
225 #[stable(feature = "rust1", since = "1.0.0")]
226 fn trait_stable_text(&self) {}
229 impl Trait for MethodTester {}
231 #[unstable(feature = "unstable_test_feature", issue = "none")]
232 #[rustc_deprecated(since = "1.0.0", reason = "text")]
233 pub struct DeprecatedStruct {
234 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
236 #[unstable(feature = "unstable_test_feature", issue = "none")]
237 pub struct UnstableStruct {
238 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
240 #[stable(feature = "rust1", since = "1.0.0")]
241 pub struct StableStruct {
242 #[stable(feature = "stable_test_feature", since = "1.0.0")] i: isize
245 #[unstable(feature = "unstable_test_feature", issue = "none")]
246 #[rustc_deprecated(since = "1.0.0", reason = "text")]
247 pub struct DeprecatedUnitStruct;
248 #[unstable(feature = "unstable_test_feature", issue = "none")]
249 pub struct UnstableUnitStruct;
250 #[stable(feature = "rust1", since = "1.0.0")]
251 pub struct StableUnitStruct;
254 #[unstable(feature = "unstable_test_feature", issue = "none")]
255 #[rustc_deprecated(since = "1.0.0", reason = "text")]
257 #[unstable(feature = "unstable_test_feature", issue = "none")]
260 #[stable(feature = "rust1", since = "1.0.0")]
264 #[unstable(feature = "unstable_test_feature", issue = "none")]
265 #[rustc_deprecated(since = "1.0.0", reason = "text")]
266 pub struct DeprecatedTupleStruct(isize);
267 #[unstable(feature = "unstable_test_feature", issue = "none")]
268 pub struct UnstableTupleStruct(isize);
269 #[stable(feature = "rust1", since = "1.0.0")]
270 pub struct StableTupleStruct(isize);
273 // Only the deprecated cases of the following should generate
274 // errors, because other stability attributes now have meaning
275 // only *across* crates, not within a single crate.
277 type Foo = MethodTester;
278 let foo = MethodTester;
281 foo.method_deprecated();
282 Foo::method_deprecated(&foo);
283 <Foo>::method_deprecated(&foo);
284 foo.trait_deprecated();
285 Trait::trait_deprecated(&foo);
286 <Foo>::trait_deprecated(&foo);
287 <Foo as Trait>::trait_deprecated(&foo);
290 foo.method_deprecated_text();
291 Foo::method_deprecated_text(&foo);
292 <Foo>::method_deprecated_text(&foo);
293 foo.trait_deprecated_text();
294 Trait::trait_deprecated_text(&foo);
295 <Foo>::trait_deprecated_text(&foo);
296 <Foo as Trait>::trait_deprecated_text(&foo);
299 foo.method_unstable();
300 Foo::method_unstable(&foo);
301 <Foo>::method_unstable(&foo);
302 foo.trait_unstable();
303 Trait::trait_unstable(&foo);
304 <Foo>::trait_unstable(&foo);
305 <Foo as Trait>::trait_unstable(&foo);
308 foo.method_unstable_text();
309 Foo::method_unstable_text(&foo);
310 <Foo>::method_unstable_text(&foo);
311 foo.trait_unstable_text();
312 Trait::trait_unstable_text(&foo);
313 <Foo>::trait_unstable_text(&foo);
314 <Foo as Trait>::trait_unstable_text(&foo);
318 Foo::method_stable(&foo);
319 <Foo>::method_stable(&foo);
321 Trait::trait_stable(&foo);
322 <Foo>::trait_stable(&foo);
323 <Foo as Trait>::trait_stable(&foo);
326 foo.method_stable_text();
327 Foo::method_stable_text(&foo);
328 <Foo>::method_stable_text(&foo);
329 foo.trait_stable_text();
330 Trait::trait_stable_text(&foo);
331 <Foo>::trait_stable_text(&foo);
332 <Foo as Trait>::trait_stable_text(&foo);
334 let _ = DeprecatedStruct {
337 let _ = UnstableStruct { i: 0 };
338 let _ = StableStruct { i: 0 };
340 let _ = DeprecatedUnitStruct;
341 let _ = UnstableUnitStruct;
342 let _ = StableUnitStruct;
344 let _ = Enum::DeprecatedVariant;
345 let _ = Enum::UnstableVariant;
346 let _ = Enum::StableVariant;
348 let _ = DeprecatedTupleStruct (1);
349 let _ = UnstableTupleStruct (1);
350 let _ = StableTupleStruct (1);
353 fn test_method_param<Foo: Trait>(foo: Foo) {
354 foo.trait_deprecated();
355 Trait::trait_deprecated(&foo);
356 <Foo>::trait_deprecated(&foo);
357 <Foo as Trait>::trait_deprecated(&foo);
358 foo.trait_deprecated_text();
359 Trait::trait_deprecated_text(&foo);
360 <Foo>::trait_deprecated_text(&foo);
361 <Foo as Trait>::trait_deprecated_text(&foo);
362 foo.trait_unstable();
363 Trait::trait_unstable(&foo);
364 <Foo>::trait_unstable(&foo);
365 <Foo as Trait>::trait_unstable(&foo);
366 foo.trait_unstable_text();
367 Trait::trait_unstable_text(&foo);
368 <Foo>::trait_unstable_text(&foo);
369 <Foo as Trait>::trait_unstable_text(&foo);
371 Trait::trait_stable(&foo);
372 <Foo>::trait_stable(&foo);
373 <Foo as Trait>::trait_stable(&foo);
376 fn test_method_object(foo: &dyn Trait) {
377 foo.trait_deprecated();
378 foo.trait_deprecated_text();
379 foo.trait_unstable();
380 foo.trait_unstable_text();
384 #[unstable(feature = "unstable_test_feature", issue = "none")]
385 #[rustc_deprecated(since = "1.0.0", reason = "text")]
392 #[unstable(feature = "unstable_test_feature", issue = "none")]
393 #[rustc_deprecated(since = "1.0.0", reason = "text")]
394 fn test_method_body(&self) {
400 #[unstable(feature = "unstable_test_feature", issue = "none")]
401 #[rustc_deprecated(since = "1.0.0", reason = "text")]
402 pub trait DeprecatedTrait {
408 impl DeprecatedTrait for S { }
410 trait LocalTrait : DeprecatedTrait { }