Skip to content

Commit ff17cf8

Browse files
committed
Suggest use another lifetime specifier instead of underscore lifetime
Signed-off-by: xizheyin <[email protected]>
1 parent f191420 commit ff17cf8

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

compiler/rustc_resolve/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ resolve_undeclared_label =
432432
433433
resolve_underscore_lifetime_is_reserved = `'_` cannot be used here
434434
.label = `'_` is a reserved lifetime name
435+
.help = use another lifetime specifier
435436
436437
resolve_unexpected_res_change_ty_to_const_param_sugg =
437438
you might have meant to write a const parameter here

compiler/rustc_resolve/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ pub(crate) struct ImplicitElidedLifetimeNotAllowedHere {
934934

935935
#[derive(Diagnostic)]
936936
#[diag(resolve_underscore_lifetime_is_reserved, code = E0637)]
937+
#[help]
937938
pub(crate) struct UnderscoreLifetimeIsReserved {
938939
#[primary_span]
939940
#[label]

tests/ui/error-codes/E0637.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0637]: `'_` cannot be used here
33
|
44
LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
55
| ^^ `'_` is a reserved lifetime name
6+
|
7+
= help: use another lifetime specifier
68

79
error[E0106]: missing lifetime specifier
810
--> $DIR/E0637.rs:1:62

tests/ui/underscore-lifetime/in-binder.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,48 @@ error[E0637]: `'_` cannot be used here
33
|
44
LL | impl<'_> IceCube<'_> {}
55
| ^^ `'_` is a reserved lifetime name
6+
|
7+
= help: use another lifetime specifier
68

79
error[E0637]: `'_` cannot be used here
810
--> $DIR/in-binder.rs:12:15
911
|
1012
LL | struct Struct<'_> {
1113
| ^^ `'_` is a reserved lifetime name
14+
|
15+
= help: use another lifetime specifier
1216

1317
error[E0637]: `'_` cannot be used here
1418
--> $DIR/in-binder.rs:17:11
1519
|
1620
LL | enum Enum<'_> {
1721
| ^^ `'_` is a reserved lifetime name
22+
|
23+
= help: use another lifetime specifier
1824

1925
error[E0637]: `'_` cannot be used here
2026
--> $DIR/in-binder.rs:22:13
2127
|
2228
LL | union Union<'_> {
2329
| ^^ `'_` is a reserved lifetime name
30+
|
31+
= help: use another lifetime specifier
2432

2533
error[E0637]: `'_` cannot be used here
2634
--> $DIR/in-binder.rs:27:13
2735
|
2836
LL | trait Trait<'_> {
2937
| ^^ `'_` is a reserved lifetime name
38+
|
39+
= help: use another lifetime specifier
3040

3141
error[E0637]: `'_` cannot be used here
3242
--> $DIR/in-binder.rs:31:8
3343
|
3444
LL | fn foo<'_>() {
3545
| ^^ `'_` is a reserved lifetime name
46+
|
47+
= help: use another lifetime specifier
3648

3749
error: aborting due to 6 previous errors
3850

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ edition: 2021
2+
3+
fn f<'r#_>(){}
4+
//~^ ERROR `_` cannot be a raw lifetime
5+
//~| ERROR `'_` cannot be used here [E0637]
6+
7+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: `_` cannot be a raw lifetime
2+
--> $DIR/raw-annomy-lifetime-issue-143152.rs:3:6
3+
|
4+
LL | fn f<'r#_>(){}
5+
| ^^^^
6+
7+
error[E0637]: `'_` cannot be used here
8+
--> $DIR/raw-annomy-lifetime-issue-143152.rs:3:6
9+
|
10+
LL | fn f<'r#_>(){}
11+
| ^^^^ `'_` is a reserved lifetime name
12+
|
13+
= help: use another lifetime specifier
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0637`.

tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ error[E0637]: `'_` cannot be used here
1515
|
1616
LL | fn foo<'_>
1717
| ^^ `'_` is a reserved lifetime name
18+
|
19+
= help: use another lifetime specifier
1820

1921
error[E0637]: `'_` cannot be used here
2022
--> $DIR/underscore-lifetime-binders.rs:10:25
2123
|
2224
LL | fn meh() -> Box<dyn for<'_> Meh<'_>>
2325
| ^^ `'_` is a reserved lifetime name
26+
|
27+
= help: use another lifetime specifier
2428

2529
error[E0106]: missing lifetime specifier
2630
--> $DIR/underscore-lifetime-binders.rs:10:33

0 commit comments

Comments
 (0)