Issue with generic impl not compiling


#1

This is an example of my code. The error says there are conflicting implementations of trait Foo<std::vec::Vec<u8>> but I don’t see why this happens because the third impl should only be happening where S: Foo and I didn’t impl Foo.

https://play.rust-lang.org/?gist=aacf81d45925f592422f4dd1cba247ea

use std::io::Read;

fn main() {
}

trait Foo<T> {
    fn example() -> String;
}

impl<S> Foo<Vec<u8>> for S where S: Read {
    fn example() -> String {
        String::from("Vec<u8>")
    }
}

impl<S> Foo<u32> for S where S: Read {
    fn example() -> String {
        String::from("u32")
    }
}

impl<S,T> Foo<Vec<T>> for S where S: Foo<T> {
    fn example() -> String {
        String::from("anything")
    }
}

It works if in the last impl I switch from S to an actual type.
For example: https://play.rust-lang.org/?gist=f0ffa5cc05e33d45acebd2e49ca2f238


#2

In the third trait, replace T with u8, and the problem should be clear. Note that nothing says that a struct cannot implement both Read and Foo<u8>.

I think default impls RFC is supposed to help with it, but currently it’s not implemented, even in nightly compiler.