]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lint-stability.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / compile-fail / lint-stability.rs
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.
4 //
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.
10
11 // aux-build:lint_stability.rs
12 // aux-build:inherited_stability.rs
13 // aux-build:stability_cfg1.rs
14 // aux-build:stability_cfg2.rs
15
16 #![deny(deprecated)]
17 #![allow(dead_code)]
18 #![feature(staged_api)]
19 #![staged_api]
20
21 #[macro_use]
22 extern crate lint_stability;
23
24 mod cross_crate {
25 extern crate stability_cfg1;
26 extern crate stability_cfg2; //~ ERROR use of unstable library feature
27
28 use lint_stability::*;
29
30 fn test() {
31 type Foo = MethodTester;
32 let foo = MethodTester;
33
34 deprecated(); //~ ERROR use of deprecated item
35 foo.method_deprecated(); //~ ERROR use of deprecated item
36 Foo::method_deprecated(&foo); //~ ERROR use of deprecated item
37 <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated item
38 foo.trait_deprecated(); //~ ERROR use of deprecated item
39 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item
40 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item
41 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item
42
43 deprecated_text(); //~ ERROR use of deprecated item: text
44 foo.method_deprecated_text(); //~ ERROR use of deprecated item: text
45 Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated item: text
46 <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated item: text
47 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
48 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
49 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
50 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
51
52 deprecated_unstable(); //~ ERROR use of deprecated item
53 //~^ ERROR use of unstable library feature
54 foo.method_deprecated_unstable(); //~ ERROR use of deprecated item
55 //~^ ERROR use of unstable library feature
56 Foo::method_deprecated_unstable(&foo); //~ ERROR use of deprecated item
57 //~^ ERROR use of unstable library feature
58 <Foo>::method_deprecated_unstable(&foo); //~ ERROR use of deprecated item
59 //~^ ERROR use of unstable library feature
60 foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item
61 //~^ ERROR use of unstable library feature
62 Trait::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item
63 //~^ ERROR use of unstable library feature
64 <Foo>::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item
65 //~^ ERROR use of unstable library feature
66 <Foo as Trait>::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item
67 //~^ ERROR use of unstable library feature
68
69 deprecated_unstable_text(); //~ ERROR use of deprecated item: text
70 //~^ ERROR use of unstable library feature
71 foo.method_deprecated_unstable_text(); //~ ERROR use of deprecated item: text
72 //~^ ERROR use of unstable library feature
73 Foo::method_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text
74 //~^ ERROR use of unstable library feature
75 <Foo>::method_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text
76 //~^ ERROR use of unstable library feature
77 foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text
78 //~^ ERROR use of unstable library feature
79 Trait::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text
80 //~^ ERROR use of unstable library feature
81 <Foo>::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text
82 //~^ ERROR use of unstable library feature
83 <Foo as Trait>::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text
84 //~^ ERROR use of unstable library feature
85
86 unstable(); //~ ERROR use of unstable library feature
87 foo.method_unstable(); //~ ERROR use of unstable library feature
88 Foo::method_unstable(&foo); //~ ERROR use of unstable library feature
89 <Foo>::method_unstable(&foo); //~ ERROR use of unstable library feature
90 foo.trait_unstable(); //~ ERROR use of unstable library feature
91 Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature
92 <Foo>::trait_unstable(&foo); //~ ERROR use of unstable library feature
93 <Foo as Trait>::trait_unstable(&foo); //~ ERROR use of unstable library feature
94
95 unstable_text();
96 //~^ ERROR use of unstable library feature 'test_feature': text
97 foo.method_unstable_text();
98 //~^ ERROR use of unstable library feature 'test_feature': text
99 Foo::method_unstable_text(&foo);
100 //~^ ERROR use of unstable library feature 'test_feature': text
101 <Foo>::method_unstable_text(&foo);
102 //~^ ERROR use of unstable library feature 'test_feature': text
103 foo.trait_unstable_text();
104 //~^ ERROR use of unstable library feature 'test_feature': text
105 Trait::trait_unstable_text(&foo);
106 //~^ ERROR use of unstable library feature 'test_feature': text
107 <Foo>::trait_unstable_text(&foo);
108 //~^ ERROR use of unstable library feature 'test_feature': text
109 <Foo as Trait>::trait_unstable_text(&foo);
110 //~^ ERROR use of unstable library feature 'test_feature': text
111
112 stable();
113 foo.method_stable();
114 Foo::method_stable(&foo);
115 <Foo>::method_stable(&foo);
116 foo.trait_stable();
117 Trait::trait_stable(&foo);
118 <Foo>::trait_stable(&foo);
119 <Foo as Trait>::trait_stable(&foo);
120
121 stable_text();
122 foo.method_stable_text();
123 Foo::method_stable_text(&foo);
124 <Foo>::method_stable_text(&foo);
125 foo.trait_stable_text();
126 Trait::trait_stable_text(&foo);
127 <Foo>::trait_stable_text(&foo);
128 <Foo as Trait>::trait_stable_text(&foo);
129
130 let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
131 let _ = DeprecatedUnstableStruct { i: 0 }; //~ ERROR use of deprecated item
132 //~^ ERROR use of unstable library feature
133 let _ = UnstableStruct { i: 0 }; //~ ERROR use of unstable library feature
134 let _ = StableStruct { i: 0 };
135
136 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
137 let _ = DeprecatedUnstableUnitStruct; //~ ERROR use of deprecated item
138 //~^ ERROR use of unstable library feature
139 let _ = UnstableUnitStruct; //~ ERROR use of unstable library feature
140 let _ = StableUnitStruct;
141
142 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item
143 let _ = Enum::DeprecatedUnstableVariant; //~ ERROR use of deprecated item
144 //~^ ERROR use of unstable library feature
145 let _ = Enum::UnstableVariant; //~ ERROR use of unstable library feature
146 let _ = Enum::StableVariant;
147
148 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
149 let _ = DeprecatedUnstableTupleStruct (1); //~ ERROR use of deprecated item
150 //~^ ERROR use of unstable library feature
151 let _ = UnstableTupleStruct (1); //~ ERROR use of unstable library feature
152 let _ = StableTupleStruct (1);
153
154 // At the moment, the lint checker only checks stability in
155 // in the arguments of macros.
156 // Eventually, we will want to lint the contents of the
157 // macro in the module *defining* it. Also, stability levels
158 // on macros themselves are not yet linted.
159 macro_test_arg!(deprecated_text()); //~ ERROR use of deprecated item: text
160 macro_test_arg!(deprecated_unstable_text()); //~ ERROR use of deprecated item: text
161 //~^ ERROR use of unstable library feature
162 macro_test_arg!(macro_test_arg!(deprecated_text())); //~ ERROR use of deprecated item: text
163 }
164
165 fn test_method_param<Foo: Trait>(foo: Foo) {
166 foo.trait_deprecated(); //~ ERROR use of deprecated item
167 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item
168 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item
169 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item
170 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
171 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
172 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
173 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
174 foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item
175 //~^ ERROR use of unstable library feature
176 Trait::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item
177 //~^ ERROR use of unstable library feature
178 <Foo>::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item
179 //~^ ERROR use of unstable library feature
180 <Foo as Trait>::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item
181 //~^ ERROR use of unstable library feature
182 foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text
183 //~^ ERROR use of unstable library feature
184 Trait::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text
185 //~^ ERROR use of unstable library feature
186 <Foo>::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text
187 //~^ ERROR use of unstable library feature
188 <Foo as Trait>::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text
189 //~^ ERROR use of unstable library feature
190 foo.trait_unstable(); //~ ERROR use of unstable library feature
191 Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature
192 <Foo>::trait_unstable(&foo); //~ ERROR use of unstable library feature
193 <Foo as Trait>::trait_unstable(&foo); //~ ERROR use of unstable library feature
194 foo.trait_unstable_text();
195 //~^ ERROR use of unstable library feature 'test_feature': text
196 Trait::trait_unstable_text(&foo);
197 //~^ ERROR use of unstable library feature 'test_feature': text
198 <Foo>::trait_unstable_text(&foo);
199 //~^ ERROR use of unstable library feature 'test_feature': text
200 <Foo as Trait>::trait_unstable_text(&foo);
201 //~^ ERROR use of unstable library feature 'test_feature': text
202 foo.trait_stable();
203 Trait::trait_stable(&foo);
204 <Foo>::trait_stable(&foo);
205 <Foo as Trait>::trait_stable(&foo);
206 }
207
208 fn test_method_object(foo: &Trait) {
209 foo.trait_deprecated(); //~ ERROR use of deprecated item
210 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
211 foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item
212 //~^ ERROR use of unstable library feature
213 foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text
214 //~^ ERROR use of unstable library feature
215 foo.trait_unstable(); //~ ERROR use of unstable library feature
216 foo.trait_unstable_text();
217 //~^ ERROR use of unstable library feature 'test_feature': text
218 foo.trait_stable();
219 }
220
221 struct S;
222
223 impl UnstableTrait for S { } //~ ERROR use of unstable library feature
224
225 trait LocalTrait : UnstableTrait { } //~ ERROR use of unstable library feature
226
227 impl Trait for S {
228 fn trait_stable(&self) {}
229 fn trait_unstable(&self) {} //~ ERROR use of unstable library feature
230 }
231 }
232
233 mod inheritance {
234 extern crate inherited_stability; //~ ERROR use of unstable library feature
235 use self::inherited_stability::*; //~ ERROR use of unstable library feature
236
237 fn test_inheritance() {
238 unstable(); //~ ERROR use of unstable library feature
239 stable();
240
241 stable_mod::unstable(); //~ ERROR use of unstable library feature
242 stable_mod::stable();
243
244 unstable_mod::deprecated(); //~ ERROR use of deprecated item
245 unstable_mod::unstable(); //~ ERROR use of unstable library feature
246
247 let _ = Unstable::UnstableVariant; //~ ERROR use of unstable library feature
248 let _ = Unstable::StableVariant;
249
250 let x: usize = 0;
251 x.unstable(); //~ ERROR use of unstable library feature
252 x.stable();
253 }
254 }
255
256 mod this_crate {
257 #[unstable(feature = "test_feature")]
258 #[deprecated(since = "1.0.0")]
259 pub fn deprecated() {}
260 #[unstable(feature = "test_feature")]
261 #[deprecated(since = "1.0.0", reason = "text")]
262 pub fn deprecated_text() {}
263
264 #[unstable(feature = "test_feature")]
265 pub fn unstable() {}
266 #[unstable(feature = "test_feature", reason = "text")]
267 pub fn unstable_text() {}
268
269 #[stable(feature = "rust1", since = "1.0.0")]
270 pub fn stable() {}
271 #[stable(feature = "rust1", since = "1.0.0", reason = "text")]
272 pub fn stable_text() {}
273
274 #[stable(feature = "rust1", since = "1.0.0")]
275 pub struct MethodTester;
276
277 impl MethodTester {
278 #[unstable(feature = "test_feature")]
279 #[deprecated(since = "1.0.0")]
280 pub fn method_deprecated(&self) {}
281 #[unstable(feature = "test_feature")]
282 #[deprecated(since = "1.0.0", reason = "text")]
283 pub fn method_deprecated_text(&self) {}
284
285 #[unstable(feature = "test_feature")]
286 pub fn method_unstable(&self) {}
287 #[unstable(feature = "test_feature", reason = "text")]
288 pub fn method_unstable_text(&self) {}
289
290 #[stable(feature = "rust1", since = "1.0.0")]
291 pub fn method_stable(&self) {}
292 #[stable(feature = "rust1", since = "1.0.0", reason = "text")]
293 pub fn method_stable_text(&self) {}
294 }
295
296 pub trait Trait {
297 #[unstable(feature = "test_feature")]
298 #[deprecated(since = "1.0.0")]
299 fn trait_deprecated(&self) {}
300 #[unstable(feature = "test_feature")]
301 #[deprecated(since = "1.0.0", reason = "text")]
302 fn trait_deprecated_text(&self) {}
303
304 #[unstable(feature = "test_feature")]
305 fn trait_unstable(&self) {}
306 #[unstable(feature = "test_feature", reason = "text")]
307 fn trait_unstable_text(&self) {}
308
309 #[stable(feature = "rust1", since = "1.0.0")]
310 fn trait_stable(&self) {}
311 #[stable(feature = "rust1", since = "1.0.0", reason = "text")]
312 fn trait_stable_text(&self) {}
313 }
314
315 impl Trait for MethodTester {}
316
317 #[unstable(feature = "test_feature")]
318 #[deprecated(since = "1.0.0")]
319 pub struct DeprecatedStruct {
320 #[stable(feature = "test_feature", since = "1.0.0")] i: isize
321 }
322 #[unstable(feature = "test_feature")]
323 pub struct UnstableStruct {
324 #[stable(feature = "test_feature", since = "1.0.0")] i: isize
325 }
326 #[stable(feature = "rust1", since = "1.0.0")]
327 pub struct StableStruct {
328 #[stable(feature = "test_feature", since = "1.0.0")] i: isize
329 }
330
331 #[unstable(feature = "test_feature")]
332 #[deprecated(since = "1.0.0")]
333 pub struct DeprecatedUnitStruct;
334 #[unstable(feature = "test_feature")]
335 pub struct UnstableUnitStruct;
336 #[stable(feature = "rust1", since = "1.0.0")]
337 pub struct StableUnitStruct;
338
339 pub enum Enum {
340 #[unstable(feature = "test_feature")]
341 #[deprecated(since = "1.0.0")]
342 DeprecatedVariant,
343 #[unstable(feature = "test_feature")]
344 UnstableVariant,
345
346 #[stable(feature = "rust1", since = "1.0.0")]
347 StableVariant,
348 }
349
350 #[unstable(feature = "test_feature")]
351 #[deprecated(since = "1.0.0")]
352 pub struct DeprecatedTupleStruct(isize);
353 #[unstable(feature = "test_feature")]
354 pub struct UnstableTupleStruct(isize);
355 #[stable(feature = "rust1", since = "1.0.0")]
356 pub struct StableTupleStruct(isize);
357
358 fn test() {
359 // Only the deprecated cases of the following should generate
360 // errors, because other stability attributes now have meaning
361 // only *across* crates, not within a single crate.
362
363 type Foo = MethodTester;
364 let foo = MethodTester;
365
366 deprecated(); //~ ERROR use of deprecated item
367 foo.method_deprecated(); //~ ERROR use of deprecated item
368 Foo::method_deprecated(&foo); //~ ERROR use of deprecated item
369 <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated item
370 foo.trait_deprecated(); //~ ERROR use of deprecated item
371 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item
372 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item
373 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item
374
375 deprecated_text(); //~ ERROR use of deprecated item: text
376 foo.method_deprecated_text(); //~ ERROR use of deprecated item: text
377 Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated item: text
378 <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated item: text
379 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
380 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
381 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
382 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
383
384 unstable();
385 foo.method_unstable();
386 Foo::method_unstable(&foo);
387 <Foo>::method_unstable(&foo);
388 foo.trait_unstable();
389 Trait::trait_unstable(&foo);
390 <Foo>::trait_unstable(&foo);
391 <Foo as Trait>::trait_unstable(&foo);
392
393 unstable_text();
394 foo.method_unstable_text();
395 Foo::method_unstable_text(&foo);
396 <Foo>::method_unstable_text(&foo);
397 foo.trait_unstable_text();
398 Trait::trait_unstable_text(&foo);
399 <Foo>::trait_unstable_text(&foo);
400 <Foo as Trait>::trait_unstable_text(&foo);
401
402 stable();
403 foo.method_stable();
404 Foo::method_stable(&foo);
405 <Foo>::method_stable(&foo);
406 foo.trait_stable();
407 Trait::trait_stable(&foo);
408 <Foo>::trait_stable(&foo);
409 <Foo as Trait>::trait_stable(&foo);
410
411 stable_text();
412 foo.method_stable_text();
413 Foo::method_stable_text(&foo);
414 <Foo>::method_stable_text(&foo);
415 foo.trait_stable_text();
416 Trait::trait_stable_text(&foo);
417 <Foo>::trait_stable_text(&foo);
418 <Foo as Trait>::trait_stable_text(&foo);
419
420 let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
421 let _ = UnstableStruct { i: 0 };
422 let _ = StableStruct { i: 0 };
423
424 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
425 let _ = UnstableUnitStruct;
426 let _ = StableUnitStruct;
427
428 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item
429 let _ = Enum::UnstableVariant;
430 let _ = Enum::StableVariant;
431
432 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
433 let _ = UnstableTupleStruct (1);
434 let _ = StableTupleStruct (1);
435 }
436
437 fn test_method_param<Foo: Trait>(foo: Foo) {
438 foo.trait_deprecated(); //~ ERROR use of deprecated item
439 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item
440 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item
441 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item
442 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
443 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
444 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
445 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
446 foo.trait_unstable();
447 Trait::trait_unstable(&foo);
448 <Foo>::trait_unstable(&foo);
449 <Foo as Trait>::trait_unstable(&foo);
450 foo.trait_unstable_text();
451 Trait::trait_unstable_text(&foo);
452 <Foo>::trait_unstable_text(&foo);
453 <Foo as Trait>::trait_unstable_text(&foo);
454 foo.trait_stable();
455 Trait::trait_stable(&foo);
456 <Foo>::trait_stable(&foo);
457 <Foo as Trait>::trait_stable(&foo);
458 }
459
460 fn test_method_object(foo: &Trait) {
461 foo.trait_deprecated(); //~ ERROR use of deprecated item
462 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
463 foo.trait_unstable();
464 foo.trait_unstable_text();
465 foo.trait_stable();
466 }
467
468 #[unstable(feature = "test_feature")]
469 #[deprecated(since = "1.0.0")]
470 fn test_fn_body() {
471 fn fn_in_body() {}
472 fn_in_body();
473 }
474
475 impl MethodTester {
476 #[unstable(feature = "test_feature")]
477 #[deprecated(since = "1.0.0")]
478 fn test_method_body(&self) {
479 fn fn_in_body() {}
480 fn_in_body();
481 }
482 }
483
484 #[unstable(feature = "test_feature")]
485 #[deprecated(since = "1.0.0")]
486 pub trait DeprecatedTrait {
487 fn dummy(&self) { }
488 }
489
490 struct S;
491
492 impl DeprecatedTrait for S { } //~ ERROR use of deprecated item
493
494 trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item
495 }
496
497 fn main() {}