-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)C-bugCategory: This is a bug.Category: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATs`#![feature(generic_associated_types)]` a.k.a. GATs
Description
I'm getting weird error messages by combining GATs with HRTBs. Here is an example:
#![feature(generic_associated_types)]
pub trait Trait {
type Assoc<'a> where Self: 'a;
}
pub trait Foo<T: Trait>
where
for<'a> T::Assoc<'a>: Clone
{}
pub struct Type;
impl<T: Trait> Foo<T> for Type
where
for<'a> T::Assoc<'a>: Clone
{}
This was working fine with rustc 1.58. Now with 1.60 I get the following error message:
error[E0311]: the parameter type `T` may not live long enough
--> src/lib.rs:13:16
|
13 | impl<T: Trait> Foo<T> for Type
| -- ^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
| |
| help: consider adding an explicit lifetime bound...: `T: 'a +`
|
note: ...that is required by this bound
--> src/lib.rs:8:38
|
8 | for<'a> <T as Trait>::Assoc<'a>: Clone
| ^^^^^
There are a couple of weird things going on:
- First, it was my understanding that the
for<'a> <T as Trait>::Assoc<'a>: ...
bound is well formed and should be accepted by the compiler even though thewhere Self: 'a
bound onTrait::Assoc
means thatT
must outlive'a
. I might be wrong here. - The error message disappears if we remove the HRTB from the trait definition but not from the trait implementation.
- We can define a function with the same HRTB, and it compiles fine:
pub fn foo<T: Trait>()
where
for<'a> T::Assoc<'a>: Clone
{}
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)C-bugCategory: This is a bug.Category: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATs`#![feature(generic_associated_types)]` a.k.a. GATs