Skip to content

Commit e84c903

Browse files
authored
Rollup merge of rust-lang#74168 - JohnTitor:help-for-in-band-lifetimes, r=petrochenkov
Add a help to use `in_band_lifetimes` in nightly Fixes rust-lang#73775
2 parents fdb5f7c + a9b6476 commit e84c903

10 files changed

+78
-0
lines changed

src/librustc_resolve/late/diagnostics.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10441044
lifetime_ref
10451045
);
10461046
err.span_label(lifetime_ref.span, "undeclared lifetime");
1047+
let mut suggests_in_band = false;
10471048
for missing in &self.missing_named_lifetime_spots {
10481049
match missing {
10491050
MissingLifetimeSpot::Generics(generics) => {
@@ -1057,6 +1058,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10571058
}) {
10581059
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
10591060
} else {
1061+
suggests_in_band = true;
10601062
(generics.span, format!("<{}>", lifetime_ref))
10611063
};
10621064
err.span_suggestion(
@@ -1084,6 +1086,15 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10841086
}
10851087
}
10861088
}
1089+
if nightly_options::is_nightly_build()
1090+
&& !self.tcx.features().in_band_lifetimes
1091+
&& suggests_in_band
1092+
{
1093+
err.help(
1094+
"if you want to experiment with in-band lifetime bindings, \
1095+
add `#![feature(in_band_lifetimes)]` to the crate attributes",
1096+
);
1097+
}
10871098
err.emit();
10881099
}
10891100

src/test/ui/error-codes/E0261.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LL | fn foo(x: &'a str) { }
55
| - ^^ undeclared lifetime
66
| |
77
| help: consider introducing lifetime `'a` here: `<'a>`
8+
|
9+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
810

911
error[E0261]: use of undeclared lifetime name `'a`
1012
--> $DIR/E0261.rs:5:9
@@ -13,6 +15,8 @@ LL | struct Foo {
1315
| - help: consider introducing lifetime `'a` here: `<'a>`
1416
LL | x: &'a str,
1517
| ^^ undeclared lifetime
18+
|
19+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
1620

1721
error: aborting due to 2 previous errors
1822

src/test/ui/feature-gates/feature-gate-in_band_lifetimes.stderr

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LL | fn foo(x: &'x u8) -> &'x u8 { x }
55
| - ^^ undeclared lifetime
66
| |
77
| help: consider introducing lifetime `'x` here: `<'x>`
8+
|
9+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
810

911
error[E0261]: use of undeclared lifetime name `'x`
1012
--> $DIR/feature-gate-in_band_lifetimes.rs:3:23
@@ -13,6 +15,8 @@ LL | fn foo(x: &'x u8) -> &'x u8 { x }
1315
| - ^^ undeclared lifetime
1416
| |
1517
| help: consider introducing lifetime `'x` here: `<'x>`
18+
|
19+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
1620

1721
error[E0261]: use of undeclared lifetime name `'b`
1822
--> $DIR/feature-gate-in_band_lifetimes.rs:15:12
@@ -28,6 +32,7 @@ error[E0261]: use of undeclared lifetime name `'b`
2832
LL | fn inner_2(&self) -> &'b u8 {
2933
| ^^ undeclared lifetime
3034
|
35+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
3136
help: consider introducing lifetime `'b` here
3237
|
3338
LL | impl<'b, 'a> X<'b> {
@@ -44,13 +49,16 @@ LL | impl X<'b> {
4449
| - ^^ undeclared lifetime
4550
| |
4651
| help: consider introducing lifetime `'b` here: `<'b>`
52+
|
53+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
4754

4855
error[E0261]: use of undeclared lifetime name `'b`
4956
--> $DIR/feature-gate-in_band_lifetimes.rs:25:27
5057
|
5158
LL | fn inner_3(&self) -> &'b u8 {
5259
| ^^ undeclared lifetime
5360
|
61+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
5462
help: consider introducing lifetime `'b` here
5563
|
5664
LL | impl<'b> X<'b> {
@@ -67,13 +75,16 @@ LL | impl Y<&'a u8> {
6775
| - ^^ undeclared lifetime
6876
| |
6977
| help: consider introducing lifetime `'a` here: `<'a>`
78+
|
79+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
7080

7181
error[E0261]: use of undeclared lifetime name `'a`
7282
--> $DIR/feature-gate-in_band_lifetimes.rs:35:25
7383
|
7484
LL | fn inner(&self) -> &'a u8 {
7585
| ^^ undeclared lifetime
7686
|
87+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
7788
help: consider introducing lifetime `'a` here
7889
|
7990
LL | impl<'a> Y<&'a u8> {
@@ -89,6 +100,7 @@ error[E0261]: use of undeclared lifetime name `'b`
89100
LL | fn any_lifetime() -> &'b u8;
90101
| ^^ undeclared lifetime
91102
|
103+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
92104
help: consider introducing lifetime `'b` here
93105
|
94106
LL | trait MyTrait<'b, 'a> {
@@ -104,6 +116,7 @@ error[E0261]: use of undeclared lifetime name `'b`
104116
LL | fn borrowed_lifetime(&'b self) -> &'b u8;
105117
| ^^ undeclared lifetime
106118
|
119+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
107120
help: consider introducing lifetime `'b` here
108121
|
109122
LL | trait MyTrait<'b, 'a> {
@@ -119,6 +132,7 @@ error[E0261]: use of undeclared lifetime name `'b`
119132
LL | fn borrowed_lifetime(&'b self) -> &'b u8;
120133
| ^^ undeclared lifetime
121134
|
135+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
122136
help: consider introducing lifetime `'b` here
123137
|
124138
LL | trait MyTrait<'b, 'a> {
@@ -135,6 +149,8 @@ LL | impl MyTrait<'a> for Y<&'a u8> {
135149
| - ^^ undeclared lifetime
136150
| |
137151
| help: consider introducing lifetime `'a` here: `<'a>`
152+
|
153+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
138154

139155
error[E0261]: use of undeclared lifetime name `'a`
140156
--> $DIR/feature-gate-in_band_lifetimes.rs:50:25
@@ -143,13 +159,16 @@ LL | impl MyTrait<'a> for Y<&'a u8> {
143159
| - ^^ undeclared lifetime
144160
| |
145161
| help: consider introducing lifetime `'a` here: `<'a>`
162+
|
163+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
146164

147165
error[E0261]: use of undeclared lifetime name `'a`
148166
--> $DIR/feature-gate-in_band_lifetimes.rs:53:31
149167
|
150168
LL | fn my_lifetime(&self) -> &'a u8 { self.0 }
151169
| ^^ undeclared lifetime
152170
|
171+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
153172
help: consider introducing lifetime `'a` here
154173
|
155174
LL | impl<'a> MyTrait<'a> for Y<&'a u8> {
@@ -165,6 +184,7 @@ error[E0261]: use of undeclared lifetime name `'b`
165184
LL | fn any_lifetime() -> &'b u8 { &0 }
166185
| ^^ undeclared lifetime
167186
|
187+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
168188
help: consider introducing lifetime `'b` here
169189
|
170190
LL | impl<'b> MyTrait<'a> for Y<&'a u8> {
@@ -180,6 +200,7 @@ error[E0261]: use of undeclared lifetime name `'b`
180200
LL | fn borrowed_lifetime(&'b self) -> &'b u8 { &*self.0 }
181201
| ^^ undeclared lifetime
182202
|
203+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
183204
help: consider introducing lifetime `'b` here
184205
|
185206
LL | impl<'b> MyTrait<'a> for Y<&'a u8> {
@@ -195,6 +216,7 @@ error[E0261]: use of undeclared lifetime name `'b`
195216
LL | fn borrowed_lifetime(&'b self) -> &'b u8 { &*self.0 }
196217
| ^^ undeclared lifetime
197218
|
219+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
198220
help: consider introducing lifetime `'b` here
199221
|
200222
LL | impl<'b> MyTrait<'a> for Y<&'a u8> {

src/test/ui/generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0261]: use of undeclared lifetime name `'b`
44
LL | + Deref<Target = Self::Item<'b>>;
55
| ^^ undeclared lifetime
66
|
7+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
78
help: consider introducing lifetime `'b` here
89
|
910
LL | trait Iterable<'b> {
@@ -19,6 +20,7 @@ error[E0261]: use of undeclared lifetime name `'undeclared`
1920
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
2021
| ^^^^^^^^^^^ undeclared lifetime
2122
|
23+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
2224
help: consider introducing lifetime `'undeclared` here
2325
|
2426
LL | trait Iterable<'undeclared> {

src/test/ui/methods/method-call-lifetime-args-unresolved.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LL | fn main() {
55
| - help: consider introducing lifetime `'a` here: `<'a>`
66
LL | 0.clone::<'a>();
77
| ^^ undeclared lifetime
8+
|
9+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
810

911
error: aborting due to previous error
1012

src/test/ui/regions/regions-in-enums.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LL | enum No0 {
55
| - help: consider introducing lifetime `'foo` here: `<'foo>`
66
LL | X5(&'foo usize)
77
| ^^^^ undeclared lifetime
8+
|
9+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
810

911
error[E0261]: use of undeclared lifetime name `'a`
1012
--> $DIR/regions-in-enums.rs:17:9
@@ -13,6 +15,8 @@ LL | enum No1 {
1315
| - help: consider introducing lifetime `'a` here: `<'a>`
1416
LL | X6(&'a usize)
1517
| ^^ undeclared lifetime
18+
|
19+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
1620

1721
error: aborting due to 2 previous errors
1822

src/test/ui/regions/regions-in-structs.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LL | struct StructDecl {
55
| - help: consider introducing lifetime `'a` here: `<'a>`
66
LL | a: &'a isize,
77
| ^^ undeclared lifetime
8+
|
9+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
810

911
error[E0261]: use of undeclared lifetime name `'a`
1012
--> $DIR/regions-in-structs.rs:11:9
@@ -14,6 +16,8 @@ LL | struct StructDecl {
1416
LL | a: &'a isize,
1517
LL | b: &'a isize,
1618
| ^^ undeclared lifetime
19+
|
20+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
1721

1822
error: aborting due to 2 previous errors
1923

src/test/ui/regions/regions-name-undeclared.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0261]: use of undeclared lifetime name `'b`
44
LL | fn m4(&self, arg: &'b isize) { }
55
| ^^ undeclared lifetime
66
|
7+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
78
help: consider introducing lifetime `'b` here
89
|
910
LL | impl<'b, 'a> Foo<'a> {
@@ -19,6 +20,7 @@ error[E0261]: use of undeclared lifetime name `'b`
1920
LL | fn m5(&'b self) { }
2021
| ^^ undeclared lifetime
2122
|
23+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
2224
help: consider introducing lifetime `'b` here
2325
|
2426
LL | impl<'b, 'a> Foo<'a> {
@@ -34,6 +36,7 @@ error[E0261]: use of undeclared lifetime name `'b`
3436
LL | fn m6(&self, arg: Foo<'b>) { }
3537
| ^^ undeclared lifetime
3638
|
39+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
3740
help: consider introducing lifetime `'b` here
3841
|
3942
LL | impl<'b, 'a> Foo<'a> {
@@ -50,6 +53,8 @@ LL | type X = Option<&'a isize>;
5053
| - ^^ undeclared lifetime
5154
| |
5255
| help: consider introducing lifetime `'a` here: `<'a>`
56+
|
57+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
5358

5459
error[E0261]: use of undeclared lifetime name `'a`
5560
--> $DIR/regions-name-undeclared.rs:27:13
@@ -58,6 +63,8 @@ LL | enum E {
5863
| - help: consider introducing lifetime `'a` here: `<'a>`
5964
LL | E1(&'a isize)
6065
| ^^ undeclared lifetime
66+
|
67+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
6168

6269
error[E0261]: use of undeclared lifetime name `'a`
6370
--> $DIR/regions-name-undeclared.rs:30:13
@@ -66,6 +73,8 @@ LL | struct S {
6673
| - help: consider introducing lifetime `'a` here: `<'a>`
6774
LL | f: &'a isize
6875
| ^^ undeclared lifetime
76+
|
77+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
6978

7079
error[E0261]: use of undeclared lifetime name `'a`
7180
--> $DIR/regions-name-undeclared.rs:32:14
@@ -74,6 +83,8 @@ LL | fn f(a: &'a isize) { }
7483
| - ^^ undeclared lifetime
7584
| |
7685
| help: consider introducing lifetime `'a` here: `<'a>`
86+
|
87+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
7788

7889
error[E0261]: use of undeclared lifetime name `'a`
7990
--> $DIR/regions-name-undeclared.rs:40:17
@@ -82,6 +93,8 @@ LL | fn fn_types(a: &'a isize,
8293
| - ^^ undeclared lifetime
8394
| |
8495
| help: consider introducing lifetime `'a` here: `<'a>`
96+
|
97+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
8598

8699
error[E0261]: use of undeclared lifetime name `'b`
87100
--> $DIR/regions-name-undeclared.rs:42:36
@@ -90,6 +103,7 @@ LL | ... &'b isize,
90103
| ^^ undeclared lifetime
91104
|
92105
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
106+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
93107
help: consider introducing lifetime `'b` here
94108
|
95109
LL | fn fn_types<'b>(a: &'a isize,
@@ -106,6 +120,7 @@ LL | ... &'b isize)>,
106120
| ^^ undeclared lifetime
107121
|
108122
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
123+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
109124
help: consider introducing lifetime `'b` here
110125
|
111126
LL | fn fn_types<'b>(a: &'a isize,
@@ -123,6 +138,8 @@ LL | fn fn_types(a: &'a isize,
123138
...
124139
LL | c: &'a isize)
125140
| ^^ undeclared lifetime
141+
|
142+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
126143

127144
error: aborting due to 11 previous errors
128145

src/test/ui/regions/regions-undeclared.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ LL | enum EnumDecl {
1111
| - help: consider introducing lifetime `'a` here: `<'a>`
1212
LL | Foo(&'a isize),
1313
| ^^ undeclared lifetime
14+
|
15+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
1416

1517
error[E0261]: use of undeclared lifetime name `'a`
1618
--> $DIR/regions-undeclared.rs:5:10
@@ -20,6 +22,8 @@ LL | enum EnumDecl {
2022
LL | Foo(&'a isize),
2123
LL | Bar(&'a isize),
2224
| ^^ undeclared lifetime
25+
|
26+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
2327

2428
error[E0261]: use of undeclared lifetime name `'a`
2529
--> $DIR/regions-undeclared.rs:8:15
@@ -28,6 +32,8 @@ LL | fn fnDecl(x: &'a isize,
2832
| - ^^ undeclared lifetime
2933
| |
3034
| help: consider introducing lifetime `'a` here: `<'a>`
35+
|
36+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
3137

3238
error[E0261]: use of undeclared lifetime name `'a`
3339
--> $DIR/regions-undeclared.rs:9:15
@@ -36,6 +42,8 @@ LL | fn fnDecl(x: &'a isize,
3642
| - help: consider introducing lifetime `'a` here: `<'a>`
3743
LL | y: &'a isize)
3844
| ^^ undeclared lifetime
45+
|
46+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
3947

4048
error: aborting due to 5 previous errors
4149

src/test/ui/where-clauses/where-lifetime-resolution.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LL | fn f() where
66
LL | for<'a> dyn Trait1<'a>: Trait1<'a>, // OK
77
LL | (dyn for<'a> Trait1<'a>): Trait1<'a>,
88
| ^^ undeclared lifetime
9+
|
10+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
911

1012
error[E0261]: use of undeclared lifetime name `'b`
1113
--> $DIR/where-lifetime-resolution.rs:8:52
@@ -15,6 +17,8 @@ LL | fn f() where
1517
...
1618
LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
1719
| ^^ undeclared lifetime
20+
|
21+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
1822

1923
error: aborting due to 2 previous errors
2024

0 commit comments

Comments
 (0)