Closed as not planned
Description
Consider this code
struct N<'a>(&'a ());
trait Bound { type Inner; }
impl<'a> Bound for N<'a> { type Inner = (); }
struct Container<T: Bound>(T::Inner);
fn cast<'a>(m: &'a Container<N<'static>>) -> &'a Container<N<'a>> {
m // error, Container is invariant over T
}
Changing this to below works
struct N<'a>(&'a ());
trait Bound { type Inner; }
impl<'a> Bound for N<'a> { type Inner = (); }
struct Container<
T: Bound,
D = <T as Bound>::Inner
>(T, D);
fn cast<'a>(m: &'a Container<N<'static>>) -> &'a Container<N<'a>> {
m
}
See
Rust compiler can be smarter to detect that Innver is covariant but it does not
Metadata
Metadata
Assignees
Labels
No labels