]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/deprecation-lint.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / test / compile-fail / deprecation-lint.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:deprecation-lint.rs
12
13 #![deny(deprecated)]
14 #![allow(warnings)]
15
16 #[macro_use]
17 extern crate deprecation_lint;
18
19 mod cross_crate {
20 use deprecation_lint::*;
21
22 fn test() {
23 type Foo = MethodTester;
24 let foo = MethodTester;
25
26 deprecated(); //~ ERROR use of deprecated item
27 foo.method_deprecated(); //~ ERROR use of deprecated item
28 Foo::method_deprecated(&foo); //~ ERROR use of deprecated item
29 <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated item
30 foo.trait_deprecated(); //~ ERROR use of deprecated item
31 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item
32 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item
33 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item
34
35 deprecated_text(); //~ ERROR use of deprecated item: text
36 foo.method_deprecated_text(); //~ ERROR use of deprecated item: text
37 Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated item: text
38 <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated item: text
39 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
40 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
41 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
42 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
43
44 let _ = DeprecatedStruct { //~ ERROR use of deprecated item
45 i: 0 //~ ERROR use of deprecated item
46 };
47
48 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
49
50 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item
51
52 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
53
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 item: text
60 macro_test_arg!(macro_test_arg!(deprecated_text())); //~ ERROR use of deprecated item: text
61 }
62
63 fn test_method_param<Foo: Trait>(foo: Foo) {
64 foo.trait_deprecated(); //~ ERROR use of deprecated item
65 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item
66 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item
67 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item
68 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
69 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
70 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
71 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
72 }
73
74 fn test_method_object(foo: &Trait) {
75 foo.trait_deprecated(); //~ ERROR use of deprecated item
76 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
77 }
78
79 struct S;
80
81 impl DeprecatedTrait for S {} //~ ERROR use of deprecated item: text
82 trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item: text
83
84 pub fn foo() {
85 let x = Stable {
86 override2: 3,
87 //~^ ERROR use of deprecated item
88 };
89
90 let _ = x.override2;
91 //~^ ERROR use of deprecated item
92
93 let Stable {
94 override2: _
95 //~^ ERROR use of deprecated item
96 } = x;
97 // all fine
98 let Stable { .. } = x;
99
100 let x = Stable2(1, 2, 3);
101
102 let _ = x.2;
103 //~^ ERROR use of deprecated item
104
105 let Stable2(_,
106 _,
107 _)
108 //~^ ERROR use of deprecated item
109 = x;
110 // all fine
111 let Stable2(..) = x;
112
113 let x = Deprecated {
114 //~^ ERROR use of deprecated item
115 inherit: 1,
116 //~^ ERROR use of deprecated item
117 };
118
119 let _ = x.inherit;
120 //~^ ERROR use of deprecated item
121
122 let Deprecated {
123 //~^ ERROR use of deprecated item
124 inherit: _,
125 //~^ ERROR use of deprecated item
126 } = x;
127
128 let Deprecated
129 //~^ ERROR use of deprecated item
130 { .. } = x;
131
132 let x = Deprecated2(1, 2, 3);
133 //~^ ERROR use of deprecated item
134
135 let _ = x.0;
136 //~^ ERROR use of deprecated item
137 let _ = x.1;
138 //~^ ERROR use of deprecated item
139 let _ = x.2;
140 //~^ ERROR use of deprecated item
141
142 let Deprecated2
143 //~^ ERROR use of deprecated item
144 (_,
145 //~^ ERROR use of deprecated item
146 _,
147 //~^ ERROR use of deprecated item
148 _)
149 //~^ ERROR use of deprecated item
150 = x;
151 let Deprecated2
152 //~^ ERROR use of deprecated item
153 // the patterns are all fine:
154 (..) = x;
155 }
156 }
157
158 mod inheritance {
159 use deprecation_lint::*;
160
161 fn test_inheritance() {
162 deprecated_mod::deprecated(); //~ ERROR use of deprecated item
163 }
164 }
165
166 mod this_crate {
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() {}
171
172 pub struct MethodTester;
173
174 impl MethodTester {
175 #[deprecated(since = "1.0.0", note = "text")]
176 pub fn method_deprecated(&self) {}
177 #[deprecated(since = "1.0.0", note = "text")]
178 pub fn method_deprecated_text(&self) {}
179 }
180
181 pub trait Trait {
182 #[deprecated(since = "1.0.0", note = "text")]
183 fn trait_deprecated(&self) {}
184 #[deprecated(since = "1.0.0", note = "text")]
185 fn trait_deprecated_text(&self) {}
186 }
187
188 impl Trait for MethodTester {}
189
190 #[deprecated(since = "1.0.0", note = "text")]
191 pub struct DeprecatedStruct {
192 i: isize
193 }
194 pub struct UnstableStruct {
195 i: isize
196 }
197 pub struct StableStruct {
198 i: isize
199 }
200
201 #[deprecated(since = "1.0.0", note = "text")]
202 pub struct DeprecatedUnitStruct;
203
204 pub enum Enum {
205 #[deprecated(since = "1.0.0", note = "text")]
206 DeprecatedVariant,
207 }
208
209 #[deprecated(since = "1.0.0", note = "text")]
210 pub struct DeprecatedTupleStruct(isize);
211
212 fn test() {
213 // Only the deprecated cases of the following should generate
214 // errors, because other stability attributes now have meaning
215 // only *across* crates, not within a single crate.
216
217 type Foo = MethodTester;
218 let foo = MethodTester;
219
220 deprecated(); //~ ERROR use of deprecated item
221 foo.method_deprecated(); //~ ERROR use of deprecated item
222 Foo::method_deprecated(&foo); //~ ERROR use of deprecated item
223 <Foo>::method_deprecated(&foo); //~ ERROR use of deprecated item
224 foo.trait_deprecated(); //~ ERROR use of deprecated item
225 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item
226 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item
227 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item
228
229 deprecated_text(); //~ ERROR use of deprecated item: text
230 foo.method_deprecated_text(); //~ ERROR use of deprecated item: text
231 Foo::method_deprecated_text(&foo); //~ ERROR use of deprecated item: text
232 <Foo>::method_deprecated_text(&foo); //~ ERROR use of deprecated item: text
233 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
234 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
235 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
236 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
237
238 let _ = DeprecatedStruct {
239 //~^ ERROR use of deprecated item
240 i: 0 //~ ERROR use of deprecated item
241 };
242
243 let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
244
245 let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item
246
247 let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
248 }
249
250 fn test_method_param<Foo: Trait>(foo: Foo) {
251 foo.trait_deprecated(); //~ ERROR use of deprecated item
252 Trait::trait_deprecated(&foo); //~ ERROR use of deprecated item
253 <Foo>::trait_deprecated(&foo); //~ ERROR use of deprecated item
254 <Foo as Trait>::trait_deprecated(&foo); //~ ERROR use of deprecated item
255 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
256 Trait::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
257 <Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
258 <Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text
259 }
260
261 fn test_method_object(foo: &Trait) {
262 foo.trait_deprecated(); //~ ERROR use of deprecated item
263 foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
264 }
265
266 #[deprecated(since = "1.0.0", note = "text")]
267 fn test_fn_body() {
268 fn fn_in_body() {}
269 fn_in_body();
270 }
271
272 impl MethodTester {
273 #[deprecated(since = "1.0.0", note = "text")]
274 fn test_method_body(&self) {
275 fn fn_in_body() {}
276 fn_in_body();
277 }
278 }
279
280 #[deprecated(since = "1.0.0", note = "text")]
281 pub trait DeprecatedTrait {
282 fn dummy(&self) { }
283 }
284
285 struct S;
286
287 impl DeprecatedTrait for S { } //~ ERROR use of deprecated item
288
289 trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item
290 }
291
292 mod this_crate2 {
293 struct Stable {
294 #[deprecated(since = "1.0.0", note = "text")]
295 override2: u8,
296 }
297
298 struct Stable2(u8,
299 u8,
300 #[deprecated(since = "1.0.0", note = "text")] u8);
301
302 #[deprecated(since = "1.0.0", note = "text")]
303 struct Deprecated {
304 inherit: u8,
305 }
306
307 #[deprecated(since = "1.0.0", note = "text")]
308 struct Deprecated2(u8,
309 u8,
310 u8);
311
312 pub fn foo() {
313 let x = Stable {
314 override2: 3,
315 //~^ ERROR use of deprecated item
316 };
317
318 let _ = x.override2;
319 //~^ ERROR use of deprecated item
320
321 let Stable {
322 override2: _
323 //~^ ERROR use of deprecated item
324 } = x;
325 // all fine
326 let Stable { .. } = x;
327
328 let x = Stable2(1, 2, 3);
329
330 let _ = x.2;
331 //~^ ERROR use of deprecated item
332
333 let Stable2(_,
334 _,
335 _)
336 //~^ ERROR use of deprecated item
337 = x;
338 // all fine
339 let Stable2(..) = x;
340
341 let x = Deprecated {
342 //~^ ERROR use of deprecated item
343 inherit: 1,
344 //~^ ERROR use of deprecated item
345 };
346
347 let _ = x.inherit;
348 //~^ ERROR use of deprecated item
349
350 let Deprecated {
351 //~^ ERROR use of deprecated item
352 inherit: _,
353 //~^ ERROR use of deprecated item
354 } = x;
355
356 let Deprecated
357 //~^ ERROR use of deprecated item
358 // the patterns are all fine:
359 { .. } = x;
360
361 let x = Deprecated2(1, 2, 3);
362 //~^ ERROR use of deprecated item
363
364 let _ = x.0;
365 //~^ ERROR use of deprecated item
366 let _ = x.1;
367 //~^ ERROR use of deprecated item
368 let _ = x.2;
369 //~^ ERROR use of deprecated item
370
371 let Deprecated2
372 //~^ ERROR use of deprecated item
373 (_,
374 //~^ ERROR use of deprecated item
375 _,
376 //~^ ERROR use of deprecated item
377 _)
378 //~^ ERROR use of deprecated item
379 = x;
380 let Deprecated2
381 //~^ ERROR use of deprecated item
382 // the patterns are all fine:
383 (..) = x;
384 }
385 }
386
387 fn main() {}