Skip to content

Commit 99c4e7d

Browse files
authored
Rollup merge of #164795 - fmease:cta-eor-lint, r=fee1-dead
Extend support of lint `explicit_outlives_requirements` to checked type aliases Best reviewed by ignoring whitespace changes. Part of #112792. <sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
2 parents a81098a + dfee48c commit 99c4e7d

9 files changed

Lines changed: 252 additions & 206 deletions

‎compiler/rustc_lint/src/builtin.rs‎

Lines changed: 164 additions & 166 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Test that lint `explicit_outlives_requirements` can also trigger on CTAs.
2+
3+
//@ check-pass
4+
//@ run-rustfix
5+
6+
#![feature(checked_type_aliases)]
7+
#![warn(explicit_outlives_requirements)]
8+
#![allow(dead_code)]
9+
10+
type A0<'a, T> = &'a T; //~ WARN [explicit_outlives_requirements]
11+
12+
type A1<'a, T> = &'a T; //~ WARN [explicit_outlives_requirements]
13+
14+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Test that lint `explicit_outlives_requirements` can also trigger on CTAs.
2+
3+
//@ check-pass
4+
//@ run-rustfix
5+
6+
#![feature(checked_type_aliases)]
7+
#![warn(explicit_outlives_requirements)]
8+
#![allow(dead_code)]
9+
10+
type A0<'a, T: 'a> = &'a T; //~ WARN [explicit_outlives_requirements]
11+
12+
type A1<'a, T> = &'a T where T: 'a; //~ WARN [explicit_outlives_requirements]
13+
14+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: outlives requirements can be inferred
2+
--> $DIR/lint-explicit-outlives-requirements.rs:10:14
3+
|
4+
LL | type A0<'a, T: 'a> = &'a T;
5+
| ^^^^ help: remove this bound
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-explicit-outlives-requirements.rs:7:9
9+
|
10+
LL | #![warn(explicit_outlives_requirements)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
warning: outlives requirements can be inferred
14+
--> $DIR/lint-explicit-outlives-requirements.rs:12:23
15+
|
16+
LL | type A1<'a, T> = &'a T where T: 'a;
17+
| ^^^^^^^^^^^^ help: remove this bound
18+
19+
warning: 2 warnings emitted
20+

‎tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.fixed‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod everything_inside {
4040
('b: 'a) => {
4141
struct Foo<'a, 'b>(&'a &'b ());
4242
//~^ ERROR: outlives requirements can be inferred
43-
struct Bar<'a, 'b>(&'a &'b ()) ;
43+
struct Bar<'a, 'b>(&'a &'b ());
4444
//~^ ERROR: outlives requirements can be inferred
4545
struct Baz<'a, 'b>(&'a &'b ()) where (): Sized, ;
4646
//~^ ERROR: outlives requirements can be inferred
@@ -54,7 +54,7 @@ mod inner_lifetime_outside_colon_inside {
5454
($b:lifetime: 'a) => {
5555
struct Foo<'a, $b>(&'a &$b ());
5656
//~^ ERROR: outlives requirements can be inferred
57-
struct Bar<'a, $b>(&'a &$b ()) ;
57+
struct Bar<'a, $b>(&'a &$b ());
5858
//~^ ERROR: outlives requirements can be inferred
5959
struct Baz<'a, $b>(&'a &$b ()) where (): Sized, ;
6060
//~^ ERROR: outlives requirements can be inferred
@@ -114,7 +114,7 @@ mod everything_outside_with_tt_outer {
114114
// FIXME: replacement span is corrupted due to a collision in metavar span table.
115115
// struct Foo<$a, $b $colon $a>(&$a &$b ());
116116
// ^ ERROR: outlives requirements can be inferred
117-
struct Bar<$a, $b>(&$a &$b ()) ;
117+
struct Bar<$a, $b>(&$a &$b ());
118118
//~^ ERROR: outlives requirements can be inferred
119119
struct Baz<$a, $b>(&$a &$b ()) where (): Sized, ;
120120
//~^ ERROR: outlives requirements can be inferred
@@ -129,7 +129,7 @@ mod everything_outside_with_tt_both {
129129
// FIXME: replacement span is corrupted due to a collision in metavar span table.
130130
// struct Foo<$a, $b $colon $a>(&$a &$b ());
131131
// ^ ERROR: outlives requirements can be inferred
132-
struct Bar<$a, $b>(&$a &$b ()) ;
132+
struct Bar<$a, $b>(&$a &$b ());
133133
//~^ ERROR: outlives requirements can be inferred
134134
struct Baz<$a, $b>(&$a &$b ()) where (): Sized, ;
135135
//~^ ERROR: outlives requirements can be inferred

‎tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.stderr‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ LL | m!('b: 'a);
2828
| ---------- in this macro invocation
2929

3030
error: outlives requirements can be inferred
31-
--> $DIR/edition-lint-infer-outlives-macro.rs:43:44
31+
--> $DIR/edition-lint-infer-outlives-macro.rs:43:43
3232
|
3333
LL | macro_rules! m {
3434
...
3535
LL | struct Bar<'a, 'b>(&'a &'b ()) where 'b: 'a;
36-
| ^^^^^^^^^^^^ help: remove this bound
36+
| ^^^^^^^^^^^^^ help: remove this bound
3737
...
3838
LL | m!('b: 'a);
3939
| ---------- in this macro invocation
@@ -61,12 +61,12 @@ LL | m!('b: 'a);
6161
| ---------- in this macro invocation
6262

6363
error: outlives requirements can be inferred
64-
--> $DIR/edition-lint-infer-outlives-macro.rs:57:44
64+
--> $DIR/edition-lint-infer-outlives-macro.rs:57:43
6565
|
6666
LL | macro_rules! m {
6767
...
6868
LL | struct Bar<'a, $b>(&'a &$b ()) where $b: 'a;
69-
| ^^^^^^^^^^^^ help: remove this bound
69+
| ^^^^^^^^^^^^^ help: remove this bound
7070
...
7171
LL | m!('b: 'a);
7272
| ---------- in this macro invocation
@@ -83,12 +83,12 @@ LL | m!('b: 'a);
8383
| ---------- in this macro invocation
8484

8585
error: outlives requirements can be inferred
86-
--> $DIR/edition-lint-infer-outlives-macro.rs:117:44
86+
--> $DIR/edition-lint-infer-outlives-macro.rs:117:43
8787
|
8888
LL | macro_rules! m {
8989
...
9090
LL | struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a;
91-
| ^^^^^^^^^^^^^^^^^^ help: remove this bound
91+
| ^^^^^^^^^^^^^^^^^^^ help: remove this bound
9292
...
9393
LL | m!('b: 'a);
9494
| ---------- in this macro invocation
@@ -105,12 +105,12 @@ LL | m!('b: 'a);
105105
| ---------- in this macro invocation
106106

107107
error: outlives requirements can be inferred
108-
--> $DIR/edition-lint-infer-outlives-macro.rs:132:44
108+
--> $DIR/edition-lint-infer-outlives-macro.rs:132:43
109109
|
110110
LL | macro_rules! m {
111111
...
112112
LL | struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a;
113-
| ^^^^^^^^^^^^^^^^^^ help: remove this bound
113+
| ^^^^^^^^^^^^^^^^^^^ help: remove this bound
114114
...
115115
LL | m!('b: 'a);
116116
| ---------- in this macro invocation

‎tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-multispan.stderr‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ error: outlives requirements can be inferred
271271
--> $DIR/edition-lint-infer-outlives-multispan.rs:130:46
272272
|
273273
LL | struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: 'b;
274-
| ^^^^ ^^^^^^^^^^^
274+
| ^^^^ ^^^^^^^^^^^^
275275
|
276276
help: remove these bounds
277277
|
278278
LL - struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: 'b;
279-
LL + struct TeeOutlivesAyYooWhereBee<'a, 'b, T, U>(&'a T, &'b U) ;
279+
LL + struct TeeOutlivesAyYooWhereBee<'a, 'b, T, U>(&'a T, &'b U);
280280
|
281281

282282
error: outlives requirements can be inferred
@@ -831,12 +831,12 @@ LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15);
831831
| --------------------------------------------------------- in this macro invocation
832832

833833
error: outlives requirements can be inferred
834-
--> $DIR/edition-lint-infer-outlives-multispan.rs:374:64
834+
--> $DIR/edition-lint-infer-outlives-multispan.rs:374:63
835835
|
836836
LL | macro_rules! m {
837837
...
838838
LL | struct FullWhere<'a, $($name,)+>(&'a ($($name,)+)) where $($name: 'a,)+;
839-
| ^^^^^^^^^^^^^^^^^^ help: remove these bounds
839+
| ^^^^^^^^^^^^^^^^^^^ help: remove these bounds
840840
...
841841
LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15);
842842
| --------------------------------------------------------- in this macro invocation

‎tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.fixed‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ mod tuple_structs {
253253
struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug>(&'a &'b T);
254254
//~^ ERROR outlives requirements can be inferred
255255

256-
struct TeeWhereOutlivesAy<'a, T>(&'a T) ;
256+
struct TeeWhereOutlivesAy<'a, T>(&'a T);
257257
//~^ ERROR outlives requirements can be inferred
258258

259259
struct TeeWhereOutlivesAyIsDebug<'a, T>(&'a T) where T: Debug;
@@ -262,7 +262,7 @@ mod tuple_structs {
262262
struct TeeWhereIsDebugOutlivesAy<'a, T>(&'a T) where T: Debug;
263263
//~^ ERROR outlives requirements can be inferred
264264

265-
struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T) ;
265+
struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T);
266266
//~^ ERROR outlives requirements can be inferred
267267

268268
struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T>(&'a &'b T) where T: Debug;
@@ -295,7 +295,7 @@ mod tuple_structs {
295295
struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T, U: Debug>(&'a &'b T, U);
296296
//~^ ERROR outlives requirements can be inferred
297297

298-
struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U) ;
298+
struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U);
299299
//~^ ERROR outlives requirements can be inferred
300300

301301
struct TeeYooWhereOutlivesAyIsDebug<'a, T, U>(T, &'a U) where U: Debug;
@@ -307,7 +307,7 @@ mod tuple_structs {
307307
struct TeeOutlivesAyYooWhereIsDebug<'a, T, U>(&'a T, U) where U: Debug;
308308
//~^ ERROR outlives requirements can be inferred
309309

310-
struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) ;
310+
struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U);
311311
//~^ ERROR outlives requirements can be inferred
312312

313313
struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U>(T, &'a &'b U) where U: Debug;
@@ -328,19 +328,19 @@ mod tuple_structs {
328328
struct BeeOutlivesAy<'a, 'b>(&'a &'b ());
329329
//~^ ERROR outlives requirements can be inferred
330330

331-
struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ()) ;
331+
struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ());
332332
//~^ ERROR outlives requirements can be inferred
333333

334334
struct BeeOutlivesAyTee<'a, 'b, T>(&'a &'b T);
335335
//~^ ERROR outlives requirements can be inferred
336336

337-
struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T) ;
337+
struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T);
338338
//~^ ERROR outlives requirements can be inferred
339339

340-
struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T) ;
340+
struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T);
341341
//~^ ERROR outlives requirements can be inferred
342342

343-
struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T) ;
343+
struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T);
344344
//~^ ERROR outlives requirements can be inferred
345345

346346
struct BeeOutlivesAyTeeDebug<'a, 'b, T: Debug>(&'a &'b T);

‎tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.stderr‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ LL | struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b>(&'a &'b T);
283283
| ^^^^^^^^^^ help: remove these bounds
284284

285285
error: outlives requirements can be inferred
286-
--> $DIR/edition-lint-infer-outlives.rs:256:45
286+
--> $DIR/edition-lint-infer-outlives.rs:256:44
287287
|
288288
LL | struct TeeWhereOutlivesAy<'a, T>(&'a T) where T: 'a;
289-
| ^^^^^^^^^^^ help: remove this bound
289+
| ^^^^^^^^^^^^ help: remove this bound
290290

291291
error: outlives requirements can be inferred
292292
--> $DIR/edition-lint-infer-outlives.rs:259:61
@@ -301,10 +301,10 @@ LL | struct TeeWhereIsDebugOutlivesAy<'a, T>(&'a T) where T: Debug + 'a;
301301
| ^^^^^ help: remove this bound
302302

303303
error: outlives requirements can be inferred
304-
--> $DIR/edition-lint-infer-outlives.rs:265:56
304+
--> $DIR/edition-lint-infer-outlives.rs:265:55
305305
|
306306
LL | struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T) where T: 'a + 'b;
307-
| ^^^^^^^^^^^^^^^^ help: remove these bounds
307+
| ^^^^^^^^^^^^^^^^^ help: remove these bounds
308308

309309
error: outlives requirements can be inferred
310310
--> $DIR/edition-lint-infer-outlives.rs:268:72
@@ -367,10 +367,10 @@ LL | struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug>(&'a &'b
367367
| ^^^^^^^^^ help: remove these bounds
368368

369369
error: outlives requirements can be inferred
370-
--> $DIR/edition-lint-infer-outlives.rs:298:54
370+
--> $DIR/edition-lint-infer-outlives.rs:298:53
371371
|
372372
LL | struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U) where U: 'a;
373-
| ^^^^^^^^^^^ help: remove this bound
373+
| ^^^^^^^^^^^^ help: remove this bound
374374

375375
error: outlives requirements can be inferred
376376
--> $DIR/edition-lint-infer-outlives.rs:301:70
@@ -391,10 +391,10 @@ LL | struct TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U>(&'a T, U) where U: De
391391
| ^^^^ help: remove this bound
392392

393393
error: outlives requirements can be inferred
394-
--> $DIR/edition-lint-infer-outlives.rs:310:65
394+
--> $DIR/edition-lint-infer-outlives.rs:310:64
395395
|
396396
LL | struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) where U: 'a + 'b;
397-
| ^^^^^^^^^^^^^^^^ help: remove these bounds
397+
| ^^^^^^^^^^^^^^^^^ help: remove these bounds
398398

399399
error: outlives requirements can be inferred
400400
--> $DIR/edition-lint-infer-outlives.rs:313:81
@@ -433,10 +433,10 @@ LL | struct BeeOutlivesAy<'a, 'b: 'a>(&'a &'b ());
433433
| ^^^^ help: remove this bound
434434

435435
error: outlives requirements can be inferred
436-
--> $DIR/edition-lint-infer-outlives.rs:331:51
436+
--> $DIR/edition-lint-infer-outlives.rs:331:50
437437
|
438438
LL | struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ()) where 'b: 'a;
439-
| ^^^^^^^^^^^^ help: remove this bound
439+
| ^^^^^^^^^^^^^ help: remove this bound
440440

441441
error: outlives requirements can be inferred
442442
--> $DIR/edition-lint-infer-outlives.rs:334:35
@@ -445,22 +445,22 @@ LL | struct BeeOutlivesAyTee<'a, 'b: 'a, T>(&'a &'b T);
445445
| ^^^^ help: remove this bound
446446

447447
error: outlives requirements can be inferred
448-
--> $DIR/edition-lint-infer-outlives.rs:337:56
448+
--> $DIR/edition-lint-infer-outlives.rs:337:55
449449
|
450450
LL | struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T) where 'b: 'a;
451-
| ^^^^^^^^^^^^ help: remove this bound
451+
| ^^^^^^^^^^^^^ help: remove this bound
452452

453453
error: outlives requirements can be inferred
454-
--> $DIR/edition-lint-infer-outlives.rs:340:64
454+
--> $DIR/edition-lint-infer-outlives.rs:340:63
455455
|
456456
LL | struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'b;
457-
| ^^^^^^^^^^^^^^^^^^^ help: remove these bounds
457+
| ^^^^^^^^^^^^^^^^^^^^ help: remove these bounds
458458

459459
error: outlives requirements can be inferred
460-
--> $DIR/edition-lint-infer-outlives.rs:343:66
460+
--> $DIR/edition-lint-infer-outlives.rs:343:65
461461
|
462462
LL | struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'a + 'b;
463-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds
463+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds
464464

465465
error: outlives requirements can be inferred
466466
--> $DIR/edition-lint-infer-outlives.rs:346:40

0 commit comments

Comments
 (0)