Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a help to use in_band_lifetimes in nightly #74168

Merged
merged 2 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
lifetime_ref
);
err.span_label(lifetime_ref.span, "undeclared lifetime");
let mut suggests_in_band = false;
for missing in &self.missing_named_lifetime_spots {
match missing {
MissingLifetimeSpot::Generics(generics) => {
Expand All @@ -1057,6 +1058,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
}) {
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
} else {
suggests_in_band = true;
(generics.span, format!("<{}>", lifetime_ref))
};
err.span_suggestion(
Expand Down Expand Up @@ -1084,6 +1086,15 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
}
}
}
if nightly_options::is_nightly_build()
&& !self.tcx.features().in_band_lifetimes
&& suggests_in_band
{
err.help(
"if you want to experiment with in-band lifetime bindings, \
add `#![feature(in_band_lifetimes)]` to the crate attributes",
);
}
err.emit();
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/error-codes/E0261.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | fn foo(x: &'a str) { }
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

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

error: aborting due to 2 previous errors

Expand Down
22 changes: 22 additions & 0 deletions src/test/ui/feature-gates/feature-gate-in_band_lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | fn foo(x: &'x u8) -> &'x u8 { x }
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'x` here: `<'x>`
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

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

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

error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/feature-gate-in_band_lifetimes.rs:25:27
|
LL | fn inner_3(&self) -> &'b u8 {
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | impl<'b> X<'b> {
Expand All @@ -67,13 +75,16 @@ LL | impl Y<&'a u8> {
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/feature-gate-in_band_lifetimes.rs:35:25
|
LL | fn inner(&self) -> &'a u8 {
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'a` here
|
LL | impl<'a> Y<&'a u8> {
Expand All @@ -89,6 +100,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn any_lifetime() -> &'b u8;
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | trait MyTrait<'b, 'a> {
Expand All @@ -104,6 +116,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn borrowed_lifetime(&'b self) -> &'b u8;
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | trait MyTrait<'b, 'a> {
Expand All @@ -119,6 +132,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn borrowed_lifetime(&'b self) -> &'b u8;
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | trait MyTrait<'b, 'a> {
Expand All @@ -135,6 +149,8 @@ LL | impl MyTrait<'a> for Y<&'a u8> {
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

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

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/feature-gate-in_band_lifetimes.rs:53:31
|
LL | fn my_lifetime(&self) -> &'a u8 { self.0 }
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'a` here
|
LL | impl<'a> MyTrait<'a> for Y<&'a u8> {
Expand All @@ -165,6 +184,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn any_lifetime() -> &'b u8 { &0 }
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | impl<'b> MyTrait<'a> for Y<&'a u8> {
Expand All @@ -180,6 +200,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn borrowed_lifetime(&'b self) -> &'b u8 { &*self.0 }
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | impl<'b> MyTrait<'a> for Y<&'a u8> {
Expand All @@ -195,6 +216,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn borrowed_lifetime(&'b self) -> &'b u8 { &*self.0 }
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | impl<'b> MyTrait<'a> for Y<&'a u8> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | + Deref<Target = Self::Item<'b>>;
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | trait Iterable<'b> {
Expand All @@ -19,6 +20,7 @@ error[E0261]: use of undeclared lifetime name `'undeclared`
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
| ^^^^^^^^^^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'undeclared` here
|
LL | trait Iterable<'undeclared> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | fn main() {
| - help: consider introducing lifetime `'a` here: `<'a>`
LL | 0.clone::<'a>();
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

error: aborting due to previous error

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/regions/regions-in-enums.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | enum No0 {
| - help: consider introducing lifetime `'foo` here: `<'foo>`
LL | X5(&'foo usize)
| ^^^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

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

error: aborting due to 2 previous errors

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/regions/regions-in-structs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | struct StructDecl {
| - help: consider introducing lifetime `'a` here: `<'a>`
LL | a: &'a isize,
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

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

error: aborting due to 2 previous errors

Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/regions/regions-name-undeclared.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn m4(&self, arg: &'b isize) { }
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | impl<'b, 'a> Foo<'a> {
Expand All @@ -19,6 +20,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn m5(&'b self) { }
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | impl<'b, 'a> Foo<'a> {
Expand All @@ -34,6 +36,7 @@ error[E0261]: use of undeclared lifetime name `'b`
LL | fn m6(&self, arg: Foo<'b>) { }
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | impl<'b, 'a> Foo<'a> {
Expand All @@ -50,6 +53,8 @@ LL | type X = Option<&'a isize>;
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

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

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

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

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

error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/regions-name-undeclared.rs:42:36
Expand All @@ -90,6 +103,7 @@ LL | ... &'b isize,
| ^^ undeclared lifetime
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | fn fn_types<'b>(a: &'a isize,
Expand All @@ -106,6 +120,7 @@ LL | ... &'b isize)>,
| ^^ undeclared lifetime
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'b` here
|
LL | fn fn_types<'b>(a: &'a isize,
Expand All @@ -123,6 +138,8 @@ LL | fn fn_types(a: &'a isize,
...
LL | c: &'a isize)
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

error: aborting due to 11 previous errors

Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/regions/regions-undeclared.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ LL | enum EnumDecl {
| - help: consider introducing lifetime `'a` here: `<'a>`
LL | Foo(&'a isize),
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

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

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

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

error: aborting due to 5 previous errors

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/where-clauses/where-lifetime-resolution.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ LL | fn f() where
LL | for<'a> dyn Trait1<'a>: Trait1<'a>, // OK
LL | (dyn for<'a> Trait1<'a>): Trait1<'a>,
| ^^ undeclared lifetime
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes

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

error: aborting due to 2 previous errors

Expand Down