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