1 // aux-build:deprecation-lint.rs
7 extern crate deprecation_lint;
10 use deprecation_lint::*;
13 type Foo = MethodTester;
14 let foo = MethodTester;
16 deprecated(); //~ ERROR use of deprecated function `deprecation_lint::deprecated`
17 foo.method_deprecated(); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`
18 Foo::method_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`
19 <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`
20 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
21 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
22 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
23 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
25 deprecated_text(); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
26 foo.method_deprecated_text(); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
27 Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
28 <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
29 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
30 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
31 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
32 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
34 let _ = DeprecatedStruct { //~ ERROR use of deprecated struct `deprecation_lint::DeprecatedStruct`: text
35 i: 0 //~ ERROR use of deprecated field `deprecation_lint::DeprecatedStruct::i`: text
38 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated struct `deprecation_lint::DeprecatedUnitStruct`: text
40 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated variant `deprecation_lint::Enum::DeprecatedVariant`: text
42 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated struct `deprecation_lint::DeprecatedTupleStruct`: text
44 let _ = nested::DeprecatedStruct { //~ ERROR use of deprecated struct `deprecation_lint::nested::DeprecatedStruct`: text
45 i: 0 //~ ERROR use of deprecated field `deprecation_lint::nested::DeprecatedStruct::i`: text
48 let _ = nested::DeprecatedUnitStruct; //~ ERROR use of deprecated struct `deprecation_lint::nested::DeprecatedUnitStruct`: text
50 let _ = nested::Enum::DeprecatedVariant; //~ ERROR use of deprecated variant `deprecation_lint::nested::Enum::DeprecatedVariant`: text
52 let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated struct `deprecation_lint::nested::DeprecatedTupleStruct`: text
54 // At the moment, the lint checker only checks stability in
55 // in the arguments of macros.
56 // Eventually, we will want to lint the contents of the
57 // macro in the module *defining* it. Also, stability levels
58 // on macros themselves are not yet linted.
59 macro_test_arg!(deprecated_text()); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
60 macro_test_arg!(macro_test_arg!(deprecated_text())); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
63 fn test_method_param<Foo: Trait>(foo: Foo) {
64 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
65 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
66 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
67 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
68 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
69 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
70 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
71 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
74 fn test_method_object(foo: &Trait) {
75 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`
76 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
81 impl DeprecatedTrait for S {} //~ ERROR use of deprecated trait `deprecation_lint::DeprecatedTrait`: text
82 trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated trait `deprecation_lint::DeprecatedTrait`: text
87 //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text
91 //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text
95 //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text
98 let Stable { .. } = x;
100 let x = Stable2(1, 2, 3);
103 //~^ ERROR use of deprecated field `deprecation_lint::Stable2::2`: text
108 //~^ ERROR use of deprecated field `deprecation_lint::Stable2::2`: text
114 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
116 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text
120 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text
123 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
125 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text
129 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
132 let x = Deprecated2(1, 2, 3);
133 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated2`: text
136 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::0`: text
138 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::1`: text
140 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::2`: text
143 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated2`: text
145 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::0`: text
147 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::1`: text
149 //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::2`: text
152 //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated2`: text
153 // the patterns are all fine:
159 use deprecation_lint::*;
161 fn test_inheritance() {
162 deprecated_mod::deprecated(); //~ ERROR use of deprecated function `deprecation_lint::deprecated_mod::deprecated`: text
167 #[deprecated(since = "1.0.0", note = "text")]
168 pub fn deprecated() {}
169 #[deprecated(since = "1.0.0", note = "text")]
170 pub fn deprecated_text() {}
172 #[deprecated(since = "99.99.99", note = "text")]
173 pub fn deprecated_future() {}
174 #[deprecated(since = "99.99.99", note = "text")]
175 pub fn deprecated_future_text() {}
177 pub struct MethodTester;
180 #[deprecated(since = "1.0.0", note = "text")]
181 pub fn method_deprecated(&self) {}
182 #[deprecated(since = "1.0.0", note = "text")]
183 pub fn method_deprecated_text(&self) {}
187 #[deprecated(since = "1.0.0", note = "text")]
188 fn trait_deprecated(&self) {}
189 #[deprecated(since = "1.0.0", note = "text")]
190 fn trait_deprecated_text(&self) {}
193 impl Trait for MethodTester {}
195 #[deprecated(since = "1.0.0", note = "text")]
196 pub struct DeprecatedStruct {
199 pub struct UnstableStruct {
202 pub struct StableStruct {
206 #[deprecated(since = "1.0.0", note = "text")]
207 pub struct DeprecatedUnitStruct;
210 #[deprecated(since = "1.0.0", note = "text")]
214 #[deprecated(since = "1.0.0", note = "text")]
215 pub struct DeprecatedTupleStruct(isize);
218 #[deprecated(since = "1.0.0", note = "text")]
219 pub struct DeprecatedStruct {
223 #[deprecated(since = "1.0.0", note = "text")]
224 pub struct DeprecatedUnitStruct;
227 #[deprecated(since = "1.0.0", note = "text")]
231 #[deprecated(since = "1.0.0", note = "text")]
232 pub struct DeprecatedTupleStruct(pub isize);
238 // Only the deprecated cases of the following should generate
239 // errors, because other stability attributes now have meaning
240 // only *across* crates, not within a single crate.
242 type Foo = MethodTester;
243 let foo = MethodTester;
245 deprecated(); //~ ERROR use of deprecated function `this_crate::deprecated`
246 foo.method_deprecated(); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated`
247 Foo::method_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated`
248 <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated`
249 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
250 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
251 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
252 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
254 deprecated_text(); //~ ERROR use of deprecated function `this_crate::deprecated_text`: text
255 foo.method_deprecated_text(); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
256 Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
257 <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
258 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
259 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
260 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
261 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
263 // Future deprecations are only permitted for rustc_deprecated.
264 deprecated_future(); //~ ERROR use of deprecated function
265 deprecated_future_text(); //~ ERROR use of deprecated function
267 let _ = DeprecatedStruct {
268 //~^ ERROR use of deprecated struct `this_crate::DeprecatedStruct`: text
269 i: 0 //~ ERROR use of deprecated field `this_crate::DeprecatedStruct::i`: text
272 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `this_crate::DeprecatedUnitStruct`: text
274 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `this_crate::Enum::DeprecatedVariant`: text
276 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `this_crate::DeprecatedTupleStruct`: text
278 let _ = nested::DeprecatedStruct {
279 //~^ ERROR use of deprecated struct `this_crate::nested::DeprecatedStruct`: text
280 i: 0 //~ ERROR use of deprecated field `this_crate::nested::DeprecatedStruct::i`: text
283 let _ = nested::DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `this_crate::nested::DeprecatedUnitStruct`: text
285 let _ = nested::Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `this_crate::nested::Enum::DeprecatedVariant`: text
287 let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `this_crate::nested::DeprecatedTupleStruct`: text
290 fn test_method_param<Foo: Trait>(foo: Foo) {
291 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
292 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
293 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
294 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
295 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
296 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
297 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
298 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
301 fn test_method_object(foo: &Trait) {
302 foo.trait_deprecated(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated`
303 foo.trait_deprecated_text(); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
306 #[deprecated(since = "1.0.0", note = "text")]
312 fn test_fn_closure_body() {
316 bar(); //~ ERROR use of deprecated function `this_crate::test_fn_closure_body::{closure#0}::bar`
321 #[deprecated(since = "1.0.0", note = "text")]
322 fn test_method_body(&self) {
328 #[deprecated(since = "1.0.0", note = "text")]
329 pub trait DeprecatedTrait {
335 impl DeprecatedTrait for S { } //~ ERROR use of deprecated trait `this_crate::DeprecatedTrait`: text
337 trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated trait `this_crate::DeprecatedTrait`: text
342 #[deprecated(since = "1.0.0", note = "text")]
348 #[deprecated(since = "1.0.0", note = "text")] u8);
350 #[deprecated(since = "1.0.0", note = "text")]
355 #[deprecated(since = "1.0.0", note = "text")]
356 struct Deprecated2(u8,
363 //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text
367 //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text
371 //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text
374 let Stable { .. } = x;
376 let x = Stable2(1, 2, 3);
379 //~^ ERROR use of deprecated field `this_crate2::Stable2::2`: text
384 //~^ ERROR use of deprecated field `this_crate2::Stable2::2`: text
390 //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
392 //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text
396 //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text
399 //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
401 //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text
405 //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
406 // the patterns are all fine:
409 let x = Deprecated2(1, 2, 3);
410 //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text
413 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::0`: text
415 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::1`: text
417 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::2`: text
420 //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text
422 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::0`: text
424 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::1`: text
426 //~^ ERROR use of deprecated field `this_crate2::Deprecated2::2`: text
429 //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text
430 // the patterns are all fine:
435 #[deprecated(note = "Use something else instead")]
436 enum DeprecatedDebugEnum {
437 Variant1 { value: Option<String> },
441 impl DeprecatedDebugEnum {
443 DeprecatedDebugEnum::Variant1 { value: None }
449 let _ = DeprecatedDebugEnum::new();