-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'static lifetime suggestion when GAT implied 'static requirement …
…from HRTB
- Loading branch information
yanchen4791
committed
Jan 17, 2023
1 parent
38a76f3
commit aadd58e
Showing
7 changed files
with
258 additions
and
4 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
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
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
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
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,43 @@ | ||
// run-rustfix | ||
// | ||
#![allow(warnings)] | ||
struct Wrapper<'a, T: ?Sized>(&'a T); | ||
|
||
trait Project { | ||
type Projected<'a> where Self: 'a; | ||
fn project(this: Wrapper<'_, Self>) -> Self::Projected<'_>; | ||
} | ||
trait MyTrait {} | ||
trait ProjectedMyTrait {} | ||
|
||
impl<T> Project for Option<T> { | ||
type Projected<'a> = Option<Wrapper<'a, T>> where T: 'a; | ||
fn project(this: Wrapper<'_, Self>) -> Self::Projected<'_> { | ||
this.0.as_ref().map(Wrapper) | ||
} | ||
} | ||
|
||
impl<T: MyTrait> MyTrait for Option<Wrapper<'_, T>> {} | ||
|
||
impl<T: ProjectedMyTrait> MyTrait for Wrapper<'_, T> {} | ||
|
||
impl<T> ProjectedMyTrait for T | ||
where | ||
T: Project, | ||
for<'a> T::Projected<'a>: MyTrait, | ||
//~^ NOTE due to current limitations in the borrow checker, this implies a `'static` lifetime | ||
//~| NOTE due to current limitations in the borrow checker, this implies a `'static` lifetime | ||
{} | ||
|
||
fn require_trait<T: MyTrait>(_: T) {} | ||
|
||
fn foo<T : MyTrait + 'static + 'static, U : MyTrait + 'static + 'static>(wrap: Wrapper<'_, Option<T>>, wrap1: Wrapper<'_, Option<U>>) { | ||
//~^ HELP consider restricting the type parameter to the `'static` lifetime | ||
//~| HELP consider restricting the type parameter to the `'static` lifetime | ||
require_trait(wrap); | ||
//~^ ERROR `T` does not live long enough | ||
require_trait(wrap1); | ||
//~^ ERROR `U` does not live long enough | ||
} | ||
|
||
fn main() {} |
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,43 @@ | ||
// run-rustfix | ||
// | ||
#![allow(warnings)] | ||
struct Wrapper<'a, T: ?Sized>(&'a T); | ||
|
||
trait Project { | ||
type Projected<'a> where Self: 'a; | ||
fn project(this: Wrapper<'_, Self>) -> Self::Projected<'_>; | ||
} | ||
trait MyTrait {} | ||
trait ProjectedMyTrait {} | ||
|
||
impl<T> Project for Option<T> { | ||
type Projected<'a> = Option<Wrapper<'a, T>> where T: 'a; | ||
fn project(this: Wrapper<'_, Self>) -> Self::Projected<'_> { | ||
this.0.as_ref().map(Wrapper) | ||
} | ||
} | ||
|
||
impl<T: MyTrait> MyTrait for Option<Wrapper<'_, T>> {} | ||
|
||
impl<T: ProjectedMyTrait> MyTrait for Wrapper<'_, T> {} | ||
|
||
impl<T> ProjectedMyTrait for T | ||
where | ||
T: Project, | ||
for<'a> T::Projected<'a>: MyTrait, | ||
//~^ NOTE due to current limitations in the borrow checker, this implies a `'static` lifetime | ||
//~| NOTE due to current limitations in the borrow checker, this implies a `'static` lifetime | ||
{} | ||
|
||
fn require_trait<T: MyTrait>(_: T) {} | ||
|
||
fn foo<T : MyTrait, U : MyTrait>(wrap: Wrapper<'_, Option<T>>, wrap1: Wrapper<'_, Option<U>>) { | ||
//~^ HELP consider restricting the type parameter to the `'static` lifetime | ||
//~| HELP consider restricting the type parameter to the `'static` lifetime | ||
require_trait(wrap); | ||
//~^ ERROR `T` does not live long enough | ||
require_trait(wrap1); | ||
//~^ ERROR `U` does not live long enough | ||
} | ||
|
||
fn main() {} |
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,34 @@ | ||
error: `T` does not live long enough | ||
--> $DIR/issue-105507.rs:37:5 | ||
| | ||
LL | require_trait(wrap); | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: due to current limitations in the borrow checker, this implies a `'static` lifetime | ||
--> $DIR/issue-105507.rs:27:35 | ||
| | ||
LL | for<'a> T::Projected<'a>: MyTrait, | ||
| ^^^^^^^ | ||
help: consider restricting the type parameter to the `'static` lifetime | ||
| | ||
LL | fn foo<T : MyTrait + 'static, U : MyTrait + 'static>(wrap: Wrapper<'_, Option<T>>, wrap1: Wrapper<'_, Option<U>>) { | ||
| +++++++++ +++++++++ | ||
|
||
error: `U` does not live long enough | ||
--> $DIR/issue-105507.rs:39:5 | ||
| | ||
LL | require_trait(wrap1); | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: due to current limitations in the borrow checker, this implies a `'static` lifetime | ||
--> $DIR/issue-105507.rs:27:35 | ||
| | ||
LL | for<'a> T::Projected<'a>: MyTrait, | ||
| ^^^^^^^ | ||
help: consider restricting the type parameter to the `'static` lifetime | ||
| | ||
LL | fn foo<T : MyTrait + 'static, U : MyTrait + 'static>(wrap: Wrapper<'_, Option<T>>, wrap1: Wrapper<'_, Option<U>>) { | ||
| +++++++++ +++++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|