summaryrefslogtreecommitdiffstats
path: root/tests/ui/deprecation/deprecation-lint.rs
blob: 83056feaf274915d68e5af4e9a64aadc93781908 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
// aux-build:deprecation-lint.rs

#![deny(deprecated)]
#![allow(warnings)]

#[macro_use]
extern crate deprecation_lint;

mod cross_crate {
    use deprecation_lint::*;

    fn test() {
        type Foo = MethodTester;
        let foo = MethodTester;

        deprecated(); //~ ERROR use of deprecated function `deprecation_lint::deprecated`
        foo.method_deprecated(); //~ ERROR use of deprecated method `deprecation_lint::MethodTester::method_deprecated`
        Foo::method_deprecated(&foo); //~ ERROR use of deprecated method `deprecation_lint::MethodTester::method_deprecated`
        <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated method `deprecation_lint::MethodTester::method_deprecated`
        foo.trait_deprecated(); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`
        Trait::trait_deprecated(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`
        <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`
        <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`

        deprecated_text(); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
        foo.method_deprecated_text(); //~ ERROR use of deprecated method `deprecation_lint::MethodTester::method_deprecated_text`: text
        Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated method `deprecation_lint::MethodTester::method_deprecated_text`: text
        <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated method `deprecation_lint::MethodTester::method_deprecated_text`: text
        foo.trait_deprecated_text(); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text
        Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text
        <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text
        <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text

        let _ = DeprecatedStruct { //~ ERROR use of deprecated struct `deprecation_lint::DeprecatedStruct`: text
            i: 0 //~ ERROR use of deprecated field `deprecation_lint::DeprecatedStruct::i`: text
        };

        let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `deprecation_lint::DeprecatedUnitStruct`: text

        let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `deprecation_lint::Enum::DeprecatedVariant`: text

        let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `deprecation_lint::DeprecatedTupleStruct`: text

        let _ = nested::DeprecatedStruct { //~ ERROR use of deprecated struct `deprecation_lint::nested::DeprecatedStruct`: text
            i: 0 //~ ERROR use of deprecated field `deprecation_lint::nested::DeprecatedStruct::i`: text
        };

        let _ = nested::DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `deprecation_lint::nested::DeprecatedUnitStruct`: text

        let _ = nested::Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `deprecation_lint::nested::Enum::DeprecatedVariant`: text

        let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `deprecation_lint::nested::DeprecatedTupleStruct`: text

        // At the moment, the lint checker only checks stability
        // in the arguments of macros.
        // Eventually, we will want to lint the contents of the
        // macro in the module *defining* it. Also, stability levels
        // on macros themselves are not yet linted.
        macro_test_arg!(deprecated_text()); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
        macro_test_arg!(macro_test_arg!(deprecated_text())); //~ ERROR use of deprecated function `deprecation_lint::deprecated_text`: text
    }

    fn test_method_param<Foo: Trait>(foo: Foo) {
        foo.trait_deprecated(); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`
        Trait::trait_deprecated(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`
        <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`
        <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`
        foo.trait_deprecated_text(); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text
        Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text
        <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text
        <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text
    }

    fn test_method_object(foo: &Trait) {
        foo.trait_deprecated(); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated`
        foo.trait_deprecated_text(); //~ ERROR use of deprecated method `deprecation_lint::Trait::trait_deprecated_text`: text
    }

    struct S;

    impl DeprecatedTrait for S {} //~ ERROR use of deprecated trait `deprecation_lint::DeprecatedTrait`: text
    trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated trait `deprecation_lint::DeprecatedTrait`: text

    pub fn foo() {
        let x = Stable {
            override2: 3,
            //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text
        };

        let _ = x.override2;
        //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text

        let Stable {
            override2: _
            //~^ ERROR use of deprecated field `deprecation_lint::Stable::override2`: text
        } = x;
        // all fine
        let Stable { .. } = x;

        let x = Stable2(1, 2, 3);

        let _ = x.2;
        //~^ ERROR use of deprecated field `deprecation_lint::Stable2::2`: text

        let Stable2(_,
                   _,
                   _)
            //~^ ERROR use of deprecated field `deprecation_lint::Stable2::2`: text
            = x;
        // all fine
        let Stable2(..) = x;

        let x = Deprecated {
            //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
            inherit: 1,
            //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text
        };

        let _ = x.inherit;
        //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text

        let Deprecated {
            //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
            inherit: _,
            //~^ ERROR use of deprecated field `deprecation_lint::Deprecated::inherit`: text
        } = x;

        let Deprecated
            //~^ ERROR use of deprecated struct `deprecation_lint::Deprecated`: text
            { .. } = x;

        let x = Deprecated2(1, 2, 3);
        //~^ ERROR use of deprecated tuple struct `deprecation_lint::Deprecated2`: text

        let _ = x.0;
        //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::0`: text
        let _ = x.1;
        //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::1`: text
        let _ = x.2;
        //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::2`: text

        let Deprecated2
        //~^ ERROR use of deprecated tuple struct `deprecation_lint::Deprecated2`: text
            (_,
             //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::0`: text
             _,
             //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::1`: text
             _)
             //~^ ERROR use of deprecated field `deprecation_lint::Deprecated2::2`: text
            = x;
        let Deprecated2
        //~^ ERROR use of deprecated tuple struct `deprecation_lint::Deprecated2`: text
            // the patterns are all fine:
            (..) = x;
    }
}

mod inheritance {
    use deprecation_lint::*;

    fn test_inheritance() {
        deprecated_mod::deprecated(); //~ ERROR use of deprecated function `deprecation_lint::deprecated_mod::deprecated`: text
    }
}

mod this_crate {
    #[deprecated(since = "1.0.0", note = "text")]
    pub fn deprecated() {}
    #[deprecated(since = "1.0.0", note = "text")]
    pub fn deprecated_text() {}

    #[deprecated(since = "99.99.99", note = "text")]
    pub fn deprecated_future() {}
    #[deprecated(since = "99.99.99", note = "text")]
    pub fn deprecated_future_text() {}

    pub struct MethodTester;

    impl MethodTester {
        #[deprecated(since = "1.0.0", note = "text")]
        pub fn method_deprecated(&self) {}
        #[deprecated(since = "1.0.0", note = "text")]
        pub fn method_deprecated_text(&self) {}
    }

    pub trait Trait {
        #[deprecated(since = "1.0.0", note = "text")]
        fn trait_deprecated(&self) {}
        #[deprecated(since = "1.0.0", note = "text")]
        fn trait_deprecated_text(&self) {}
    }

    impl Trait for MethodTester {}

    #[deprecated(since = "1.0.0", note = "text")]
    pub struct DeprecatedStruct {
        i: isize
    }
    pub struct UnstableStruct {
        i: isize
    }
    pub struct StableStruct {
        i: isize
    }

    #[deprecated(since = "1.0.0", note = "text")]
    pub struct DeprecatedUnitStruct;

    pub enum Enum {
        #[deprecated(since = "1.0.0", note = "text")]
        DeprecatedVariant,
    }

    #[deprecated(since = "1.0.0", note = "text")]
    pub struct DeprecatedTupleStruct(isize);

    mod nested {
        #[deprecated(since = "1.0.0", note = "text")]
        pub struct DeprecatedStruct {
            i: isize
        }

        #[deprecated(since = "1.0.0", note = "text")]
        pub struct DeprecatedUnitStruct;

        pub enum Enum {
            #[deprecated(since = "1.0.0", note = "text")]
            DeprecatedVariant,
        }

        #[deprecated(since = "1.0.0", note = "text")]
        pub struct DeprecatedTupleStruct(pub isize);
    }

    fn test() {
        use self::nested;

        // Only the deprecated cases of the following should generate
        // errors, because other stability attributes now have meaning
        // only *across* crates, not within a single crate.

        type Foo = MethodTester;
        let foo = MethodTester;

        deprecated(); //~ ERROR use of deprecated function `this_crate::deprecated`
        foo.method_deprecated(); //~ ERROR use of deprecated method `this_crate::MethodTester::method_deprecated`
        Foo::method_deprecated(&foo); //~ ERROR use of deprecated method `this_crate::MethodTester::method_deprecated`
        <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated method `this_crate::MethodTester::method_deprecated`
        foo.trait_deprecated(); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`
        Trait::trait_deprecated(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`
        <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`
        <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`

        deprecated_text(); //~ ERROR use of deprecated function `this_crate::deprecated_text`: text
        foo.method_deprecated_text(); //~ ERROR use of deprecated method `this_crate::MethodTester::method_deprecated_text`: text
        Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated method `this_crate::MethodTester::method_deprecated_text`: text
        <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated method `this_crate::MethodTester::method_deprecated_text`: text
        foo.trait_deprecated_text(); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text
        Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text
        <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text
        <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text

        // Future deprecations are only permitted with `#![feature(staged_api)]`
        deprecated_future(); //~ ERROR use of deprecated function
        deprecated_future_text(); //~ ERROR use of deprecated function

        let _ = DeprecatedStruct {
            //~^ ERROR use of deprecated struct `this_crate::DeprecatedStruct`: text
            i: 0 //~ ERROR use of deprecated field `this_crate::DeprecatedStruct::i`: text
        };

        let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `this_crate::DeprecatedUnitStruct`: text

        let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `this_crate::Enum::DeprecatedVariant`: text

        let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `this_crate::DeprecatedTupleStruct`: text

        let _ = nested::DeprecatedStruct {
            //~^ ERROR use of deprecated struct `this_crate::nested::DeprecatedStruct`: text
            i: 0 //~ ERROR use of deprecated field `this_crate::nested::DeprecatedStruct::i`: text
            //~| ERROR field `i` of struct `this_crate::nested::DeprecatedStruct` is private
        };

        let _ = nested::DeprecatedUnitStruct; //~ ERROR use of deprecated unit struct `this_crate::nested::DeprecatedUnitStruct`: text

        let _ = nested::Enum::DeprecatedVariant; //~ ERROR use of deprecated unit variant `this_crate::nested::Enum::DeprecatedVariant`: text

        let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `this_crate::nested::DeprecatedTupleStruct`: text
    }

    fn test_method_param<Foo: Trait>(foo: Foo) {
        foo.trait_deprecated(); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`
        Trait::trait_deprecated(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`
        <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`
        <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`
        foo.trait_deprecated_text(); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text
        Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text
        <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text
        <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text
    }

    fn test_method_object(foo: &Trait) {
        foo.trait_deprecated(); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated`
        foo.trait_deprecated_text(); //~ ERROR use of deprecated method `this_crate::Trait::trait_deprecated_text`: text
    }

    #[deprecated(since = "1.0.0", note = "text")]
    fn test_fn_body() {
        fn fn_in_body() {}
        fn_in_body();
    }

    fn test_fn_closure_body() {
        let _ = || {
            #[deprecated]
            fn bar() { }
            bar(); //~ ERROR use of deprecated function `this_crate::test_fn_closure_body::{closure#0}::bar`
        };
    }

    impl MethodTester {
        #[deprecated(since = "1.0.0", note = "text")]
        fn test_method_body(&self) {
            fn fn_in_body() {}
            fn_in_body();
        }
    }

    #[deprecated(since = "1.0.0", note = "text")]
    pub trait DeprecatedTrait {
        fn dummy(&self) { }
    }

    struct S;

    impl DeprecatedTrait for S { } //~ ERROR use of deprecated trait `this_crate::DeprecatedTrait`: text

    trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated trait `this_crate::DeprecatedTrait`: text
}

mod this_crate2 {
    struct Stable {
        #[deprecated(since = "1.0.0", note = "text")]
        override2: u8,
    }

    struct Stable2(u8,
                   u8,
                   #[deprecated(since = "1.0.0", note = "text")] u8);

    #[deprecated(since = "1.0.0", note = "text")]
    struct Deprecated {
        inherit: u8,
    }

    #[deprecated(since = "1.0.0", note = "text")]
    struct Deprecated2(u8,
                       u8,
                       u8);

    pub fn foo() {
        let x = Stable {
            override2: 3,
            //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text
        };

        let _ = x.override2;
        //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text

        let Stable {
            override2: _
            //~^ ERROR use of deprecated field `this_crate2::Stable::override2`: text
        } = x;
        // all fine
        let Stable { .. } = x;

        let x = Stable2(1, 2, 3);

        let _ = x.2;
        //~^ ERROR use of deprecated field `this_crate2::Stable2::2`: text

        let Stable2(_,
                   _,
                   _)
            //~^ ERROR use of deprecated field `this_crate2::Stable2::2`: text
            = x;
        // all fine
        let Stable2(..) = x;

        let x = Deprecated {
            //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
            inherit: 1,
            //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text
        };

        let _ = x.inherit;
        //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text

        let Deprecated {
            //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
            inherit: _,
            //~^ ERROR use of deprecated field `this_crate2::Deprecated::inherit`: text
        } = x;

        let Deprecated
            //~^ ERROR use of deprecated struct `this_crate2::Deprecated`: text
            // the patterns are all fine:
            { .. } = x;

        let x = Deprecated2(1, 2, 3);
        //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text

        let _ = x.0;
        //~^ ERROR use of deprecated field `this_crate2::Deprecated2::0`: text
        let _ = x.1;
        //~^ ERROR use of deprecated field `this_crate2::Deprecated2::1`: text
        let _ = x.2;
        //~^ ERROR use of deprecated field `this_crate2::Deprecated2::2`: text

        let Deprecated2
        //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text
            (_,
             //~^ ERROR use of deprecated field `this_crate2::Deprecated2::0`: text
             _,
             //~^ ERROR use of deprecated field `this_crate2::Deprecated2::1`: text
             _)
            //~^ ERROR use of deprecated field `this_crate2::Deprecated2::2`: text
            = x;
        let Deprecated2
        //~^ ERROR use of deprecated tuple struct `this_crate2::Deprecated2`: text
            // the patterns are all fine:
            (..) = x;
    }

    #[derive(Debug)]
    #[deprecated(note = "Use something else instead")]
    enum DeprecatedDebugEnum {
        Variant1 { value: Option<String> },
    }

    #[allow(deprecated)]
    impl DeprecatedDebugEnum {
        fn new() -> Self {
            DeprecatedDebugEnum::Variant1 { value: None }
        }
    }

    #[allow(deprecated)]
    pub fn allow_dep() {
        let _ = DeprecatedDebugEnum::new();
    }
}

fn main() {}