Closed
Description
#![feature(generic_associated_types)]
pub trait A {}
impl A for &dyn A {}
impl A for Box<dyn A> {}
pub struct P<'a, T: ?Sized>(&'a T);
impl<'a, T: ?Sized> A for P<'a, T> {}
pub struct Q<T: ?Sized> {
_pd: std::marker::PhantomData<T>,
}
impl A for Q<dyn A> {}
pub trait B {
type T<'a>: A;
}
impl B for () {
// this is ok:
// type T<'a> = &'a dyn A;
// so is this:
// type T<'a> = P<'a, dyn A + 'a>;
// this is not:
type T<'a> = Box<dyn A + 'a>;
// nor is this:
// type T<'a> = Q<dyn A + 'a>;
}
// Note that this is also fine:
fn _f<'a>(_x: &'a ()) -> Box<dyn A + 'a> { todo!() }
// and so is this:
fn _g<'a>(_x: &'a ()) -> Q<dyn A + 'a> { todo!() }
Error:
error[E0308]: mismatched types
--> src/lib.rs:27:5
|
27 | type T<'a> = Box<dyn A + 'a>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected trait `A`
found trait `A`
note: the lifetime `'a` as defined on the associated item at 27:12...
--> src/lib.rs:27:12
|
27 | type T<'a> = Box<dyn A + 'a>;
| ^^
= note: ...does not necessarily outlive the static lifetime
Note also that a few months back, the nightly available did accept this type of code.
Metadata
Metadata
Assignees
Labels
Area: Generic associated types (GATs)Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsCategory: This is a bug.Diagnostics: Confusing error or lint that should be reworked.`#![feature(generic_associated_types)]` a.k.a. GATsRelevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.