Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete explanation of E0404 #43913

Closed
dridi opened this issue Aug 16, 2017 · 3 comments · Fixed by #83729
Closed

Incomplete explanation of E0404 #43913

dridi opened this issue Aug 16, 2017 · 3 comments · Fixed by #83729
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. F-trait_alias `#![feature(trait_alias)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dridi
Copy link
Contributor

dridi commented Aug 16, 2017

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).

@dridi
Copy link
Contributor Author

dridi commented Aug 16, 2017

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.

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Aug 20, 2017
@estebank estebank added F-trait_alias `#![feature(trait_alias)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 22, 2020
@estebank
Copy link
Contributor

estebank commented Jan 22, 2020

Current output (in nightly):

error[E0404]: expected trait, found type alias `Strings`
 --> file.rs:3:18
  |
3 | struct Struct<S: Strings>(S);
  |                  ^^^^^^^ type aliases cannot be used as traits
  |
  = note: did you mean to use a trait alias?

@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Jan 22, 2020
@estebank estebank added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Feb 1, 2020
@estebank
Copy link
Contributor

Current output:

error[E0404]: expected trait, found type alias `Strings`
 --> src/main.rs:3:18
  |
3 | 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
 --> src/main.rs:1:1
  |
1 | type Strings = dyn Iterator<Item=String>;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

No structured suggestion for the nightly feature (should be trait Strings = Iterator<Item=String>; and the feature flag).

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 20, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? `@estebank`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 20, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? ``@estebank``
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 20, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? ```@estebank```
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 22, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? `@estebank`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 22, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? ``@estebank``
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 22, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? ```@estebank```
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 22, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? ````@estebank````
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 22, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? `````@estebank`````
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 23, 2021
Add a suggestion when using a type alias instead of trait alias

Fixes rust-lang#43913

r? ``````@estebank``````
@bors bors closed this as completed in 8ad0821 Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. F-trait_alias `#![feature(trait_alias)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants