Open jflatow opened 11 months ago
The references / lifetimes aren't necessary, here's a slightly simpler version:
pub trait Po: Sized {
type A: MA<Self>;
}
pub trait MA<P: Po>: Sized {}
pub trait Mr<P: Po>: Sized {
type As: IntoIterator<Item = P::A>; // shouldn't be necessary?
fn a(&self) -> Self::As; // impl IntoIterator<Item = P::A>;
}
pub trait BM<P: Po<A = BMA<P, Self>>>: Mr<P> {}
pub enum BMA<P: Po<A = Self>, M: BM<P>> {
V(M, P),
}
impl<P: Po<A = Self>, M: BM<P>> MA<P> for BMA<P, M> {}
impl<P: Po<A = BMA<P, M>>, M: BM<P>> Mr<P> for M {
type As = Vec<P::A>; // shouldn't be necessary?
fn a(&self) -> Self::As { // impl IntoIterator<Item = P::A> {
Vec::<P::A>::new()
}
}
I tried this code:
I expected to see this compile.
Instead, I got the following error:
Meta
The issue happens both on stable and nightly.
Backtrace
``` $ RUST_BACKTRACE=1 rustc +stable --crate-type lib impltrait.rs error[E0308]: mismatched types --> impltrait.rs:25:9 | 24 | fn a(&self) -> Self::As where Self::As: IntoIterator- { // impl IntoIterator
- {
| -------- expected `
>::As` because of return type
25 | Vec::::new()
| ^^^^^^^^^^^^^^^^^^ expected associated type, found `Vec>`
|
= note: expected associated type `>::As`
found struct `Vec>`
= help: consider constraining the associated type `>::As` to `Vec>` or calling a method that returns `>::As`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
```