Change:
I managed to reproduce the problem with this snippet: The compiler yells E0404 at me, but fair enough I always ask it to a bit more about it :) However this time, it only says this: This is confusing because the snippet above doesn't involve the keyword so I didn't understand initially what I was doing wrong, then I read the error message again: I first tried this, and it worked, but having to repeat the whole syntax everywhere wasn't too compelling, hence the alias: 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 it ;) I'm using stable Rust 1.19.0 (on Fedora).
One more thing, even though the compiler lets me create an alias for a trait, I don't know when I can use such an alias. Maybe this should be explained too.
Current output (in nightly):
Current output: No structured suggestion for the nightly feature (should be and the feature flag).

Discussion:
struct Bar; impl Foo for Bar {} // error: `Foo` is not a trait <ins> fn baz<T: Foo>(t: T) {} // error: `Foo` is not a trait </ins> ``` Another erroneous code example: ```compile_fail,E0404 <del> struct Foo; </del> <ins> type Foo = Iterator<Item=String>; </ins> <del> fn bar<T: Foo>(t: T) {} // error: `Foo` is not a trait </del> <ins> fn bar<T: Foo>(t: T) {} // error: `Foo` is a type alias </ins> ``` Please verify that the trait's name was not misspelled or that the right

impl Foo for Bar { // ok! // functions implementation } <ins> fn baz<T: Foo>(t: T) {} // ok! </ins> ``` <del> or: </del> <ins> Alternatively, you could introduce a new trait with your desired restrictions as a super trait: </ins> ``` <del> trait Foo { // some functions } </del> <ins> # trait Foo {} # struct Bar; # impl Foo for Bar {} trait Qux: Foo {} // Anything that implements Qux also needs to implement Foo fn baz<T: Qux>(t: T) {} // also ok! ``` Finally, if you are on nightly and want to use a trait alias instead of a type alias, you should use `#![feature(trait_alias)]`: ``` #![feature(trait_alias)] trait Foo = Iterator<Item=String>; </ins> fn bar<T: Foo>(t: T) {} // ok! ```

let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a  `type` alias"; if let Some(span) = self.def_span(def_id) { <del> err.span_help(span, msg); </del> <ins> if let Ok(snip) = self.r.session.source_map().span_to_snippet(span) { // The span contains a type alias so we should be able to // replace `type` with `trait`. let snip = snip.replacen("type", "trait", 1); err.span_suggestion(span, msg, snip, Applicability::MaybeIncorrect); } else { err.span_help(span, msg); } </ins> } else { err.help(msg); }

|      ^^^ type aliases cannot be used as traits | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias <del> --> $DIR/two_files_data.rs:5:1 </del> | <del> LL | type Bar = dyn Foo; | ^^^^^^^^^^^^^^^^^^^ </del> <ins> LL | trait Bar = dyn Foo; | </ins> error: aborting due to previous error

|      ^^^ type aliases cannot be used as traits | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias <del> --> $DIR/issue-3907.rs:5:1 </del> | <del> LL | type Foo = dyn issue_3907::Foo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> LL | trait Foo = dyn issue_3907::Foo; | </ins> help: consider importing this trait instead | LL | use issue_3907::Foo;

| ------- similarly named trait `I` defined here LL | type K = dyn I; LL | impl K for isize {} <del> |      ^ |      | |      type aliases cannot be used as traits |      help: a trait with a similar name exists: `I` </del> <ins> |      ^ type aliases cannot be used as traits </ins> | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias <del> --> $DIR/issue-5035.rs:2:1 </del> | <del> LL | type K = dyn I; | ^^^^^^^^^^^^^^^ </del> <ins> LL | trait K = dyn I; | help: a trait with a similar name exists | LL | impl I for isize {} |      ^ </ins> error: aborting due to 2 previous errors

|        ^^^^^^^^^^^^^^^^^^^^^^^ type aliases cannot be used as traits | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias <del> --> $DIR/unboxed-closure-sugar-nonexistent-trait.rs:4:1 </del> | <del> LL | type Typedef = isize; | ^^^^^^^^^^^^^^^^^^^^^ </del> <ins> LL | trait Typedef = isize; | </ins> error: aborting due to 2 previous errors

<ins> // Regression test of #43913. // run-rustfix #![feature(trait_alias)] #![allow(bare_trait_objects, dead_code)] trait Strings = Iterator<Item=String>; struct Struct<S: Strings>(S); //~^ ERROR: expected trait, found type alias `Strings` fn main() {} </ins>

<ins> // Regression test of #43913. // run-rustfix #![feature(trait_alias)] #![allow(bare_trait_objects, dead_code)] type Strings = Iterator<Item=String>; struct Struct<S: Strings>(S); //~^ ERROR: expected trait, found type alias `Strings` fn main() {} </ins>

<ins> error[E0404]: expected trait, found type alias `Strings` --> $DIR/suggest-trait-alias-instead-of-type.rs:10:18 | LL | struct Struct<S: Strings>(S); |                  ^^^^^^^ type aliases cannot be used as traits | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias | LL | trait Strings = Iterator<Item=String>; | error: aborting due to previous error For more information about this error, try `rustc --explain E0404`. </ins>