Skip to content

Incomplete explanation of E0404 #43913

Closed
@dridi

Description

@dridi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.F-trait_alias`#![feature(trait_alias)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions