Description
I managed to reproduce the problem with this snippet:
type Strings = Iterator<Item=String>;
struct Struct<S: Strings>(S);
fn main() { }
The compiler yells E0404 at me, but fair enough I always ask it to --explain
a bit more about it :)
However this time, it only says this:
You tried to implement something which was not a trait on an object.
This is confusing because the snippet above doesn't involve the impl
keyword so I didn't understand initially what I was doing wrong, then I read the error message again:
error[E0404]: expected trait, found type alias `Strings`
--> test.rs:3:18
|
3 | struct Struct<S: Strings>(S);
| ^^^^^^^ type aliases cannot be used for traits
I first tried this, and it worked, but having to repeat the whole syntax everywhere wasn't too compelling, hence the alias:
struct Struct<I: Iterator<Item=String>>(I);
fn main() { }
The compiler error message makes it very clear that I can't alias a trait, but the E0404 explanation doesn't mention it at all. I hope the description could also include this use case as I've seen sometimes EXXXX explanations go over several facets of the same problem. That won't help me, but maybe others that may trip on the same problem. I would have submitted a pull request for the docs myself, but I have no idea why you can't use type aliases for traits so I can't --explain
it ;)
I'm using stable Rust 1.19.0 (on Fedora).