forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#123122 - surechen:fix_122714, r=fmease Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses. For poly-trait-ref like `for<'a> Trait<T>` in `T: for<'a> Trait<T> + 'b { }`. We should merge the hrtb lifetimes: existed `for<'a>` and suggestion `for<'b>` or will get err: [E0316] nested quantification of lifetimes fixes rust-lang#122714
- Loading branch information
Showing
3 changed files
with
207 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/ui/generics/generic-higher-ranked-lifetime-issue-122714.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![allow(dead_code)] | ||
|
||
trait Trait1<T> | ||
where T: for<'a> Trait1<T> + 'b { } //~ ERROR use of undeclared lifetime name `'b` | ||
|
||
trait Trait2<T> | ||
where | ||
T: B<'b> + for<'a> A<'a>, //~ ERROR use of undeclared lifetime name `'b` | ||
{ | ||
} | ||
|
||
trait Trait3<T> | ||
where | ||
T: B<'b> + for<'a> A<'a> + 'c {} | ||
//~^ ERROR use of undeclared lifetime name `'b` | ||
//~| ERROR use of undeclared lifetime name `'c` | ||
|
||
trait Trait4<T> | ||
where | ||
T: for<'a> A<'a> + 'x + for<'b> B<'b>, //~ ERROR use of undeclared lifetime name `'x` | ||
{ | ||
} | ||
|
||
trait A<'a> {} | ||
trait B<'a> {} | ||
|
||
|
||
fn main() {} |
92 changes: 92 additions & 0 deletions
92
tests/ui/generics/generic-higher-ranked-lifetime-issue-122714.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
error[E0261]: use of undeclared lifetime name `'b` | ||
--> $DIR/generic-higher-ranked-lifetime-issue-122714.rs:4:32 | ||
| | ||
LL | where T: for<'a> Trait1<T> + 'b { } | ||
| ^^ undeclared lifetime | ||
| | ||
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html | ||
help: consider making the bound lifetime-generic with a new `'b` lifetime | ||
| | ||
LL - where T: for<'a> Trait1<T> + 'b { } | ||
LL + where for<'b, 'a> T: Trait1<T> + 'b { } | ||
| | ||
help: consider introducing lifetime `'b` here | ||
| | ||
LL | trait Trait1<'b, T> | ||
| +++ | ||
|
||
error[E0261]: use of undeclared lifetime name `'b` | ||
--> $DIR/generic-higher-ranked-lifetime-issue-122714.rs:8:10 | ||
| | ||
LL | T: B<'b> + for<'a> A<'a>, | ||
| ^^ undeclared lifetime | ||
| | ||
help: consider making the bound lifetime-generic with a new `'b` lifetime | ||
| | ||
LL | T: for<'b> B<'b> + for<'a> A<'a>, | ||
| +++++++ | ||
help: consider making the bound lifetime-generic with a new `'b` lifetime | ||
| | ||
LL - T: B<'b> + for<'a> A<'a>, | ||
LL + for<'b, 'a> T: B<'b> + A<'a>, | ||
| | ||
help: consider introducing lifetime `'b` here | ||
| | ||
LL | trait Trait2<'b, T> | ||
| +++ | ||
|
||
error[E0261]: use of undeclared lifetime name `'b` | ||
--> $DIR/generic-higher-ranked-lifetime-issue-122714.rs:14:10 | ||
| | ||
LL | T: B<'b> + for<'a> A<'a> + 'c {} | ||
| ^^ undeclared lifetime | ||
| | ||
help: consider making the bound lifetime-generic with a new `'b` lifetime | ||
| | ||
LL | T: for<'b> B<'b> + for<'a> A<'a> + 'c {} | ||
| +++++++ | ||
help: consider making the bound lifetime-generic with a new `'b` lifetime | ||
| | ||
LL - T: B<'b> + for<'a> A<'a> + 'c {} | ||
LL + for<'b, 'a> T: B<'b> + A<'a> + 'c {} | ||
| | ||
help: consider introducing lifetime `'b` here | ||
| | ||
LL | trait Trait3<'b, T> | ||
| +++ | ||
|
||
error[E0261]: use of undeclared lifetime name `'c` | ||
--> $DIR/generic-higher-ranked-lifetime-issue-122714.rs:14:32 | ||
| | ||
LL | T: B<'b> + for<'a> A<'a> + 'c {} | ||
| ^^ undeclared lifetime | ||
| | ||
help: consider making the bound lifetime-generic with a new `'c` lifetime | ||
| | ||
LL - T: B<'b> + for<'a> A<'a> + 'c {} | ||
LL + for<'c, 'a> T: B<'b> + A<'a> + 'c {} | ||
| | ||
help: consider introducing lifetime `'c` here | ||
| | ||
LL | trait Trait3<'c, T> | ||
| +++ | ||
|
||
error[E0261]: use of undeclared lifetime name `'x` | ||
--> $DIR/generic-higher-ranked-lifetime-issue-122714.rs:20:24 | ||
| | ||
LL | T: for<'a> A<'a> + 'x + for<'b> B<'b>, | ||
| ^^ undeclared lifetime | ||
| | ||
help: consider making the bound lifetime-generic with a new `'x` lifetime | ||
| | ||
LL - T: for<'a> A<'a> + 'x + for<'b> B<'b>, | ||
LL + for<'x, 'a, 'b> T: A<'a> + 'x + B<'b>, | ||
| | ||
help: consider introducing lifetime `'x` here | ||
| | ||
LL | trait Trait4<'x, T> | ||
| +++ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0261`. |