(This is a part of a bigger problem I have, but I made a reproduction of the error)
use core::ops::Index;
struct Wrapper<Ix>(Ix);
struct Container<Ix> {
_ghost: core::marker::PhantomData<Ix>,
}
impl<Ix> Index<Wrapper<Ix>> for Container<Ix> {
type Output = ();
fn index(&self, _: Wrapper<Ix>) -> &() { unimplemented!() }
}
trait Trait {
type Assoc;
fn foo()
where
Container<Self::Assoc>: Index<Self>,
<Container<Self::Assoc> as Index<Self>>::Output: Sized;
}
impl<T> Trait for Wrapper<T> {
type Assoc = T;
fn foo()
where
Container<T>: Index<Self>,
<Container<T> as Index<Self>>::Output: Sized {}
}
But this code fails to compile (try clicking “Build” on the playground)
error[E0276]: impl has stricter requirements than trait
--> src/lib.rs:29:48
|
17 | / fn foo()
18 | | where
19 | | Container<Self::Assoc>: Index<Self>,
20 | | <Container<Self::Assoc> as Index<Self>>::Output: Sized;
| |_______________________________________________________________- definition of `foo` from trait
...
29 | <Container<T> as Index<Self>>::Output: Sized,
| ^^^^^ impl has extra requirement `<Container<T> as Index<Wrapper<T>>>::Output: Sized`
rustc
says that the impl has the stricter requirement <Container<T> as Index<Wrapper<T>>>::Output: Sized
, even though the trait has that exact bound (changing the T
to Self::Assoc
makes no difference).
Is this error intentional, and if so, what is it keeping me from doing? Either way, how can I go about fixing it and getting my code to work?