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