Skip to content

Bad error message with wrong impl trait-parameter on trait implementation #52901

Description

@lukaslueg

Given this

trait FooTrait {
    fn foo(&self, i32) {}
}

struct Foo;

impl FooTrait for Foo {
    fn foo(&self, bar: &FooTrait) {}
}

The full error message is

error[E0053]: method `foo` has an incompatible type for trait
 --> src/main.rs:8:24
  |
2 |     fn foo(&self, i32) {}
  |                   --- type in trait
...
8 |     fn foo(&self, bar: &FooTrait) {}
  |                        ^^^^^^^^^ expected i32, found &FooTrait
  |
  = note: expected type `fn(&Foo, i32)`
             found type `fn(&Foo, &FooTrait)`

which is nice. However, when using &impl FooTrait instead of &FooTrait for bar in the impl FooTrait for Foo, the full error message degenerates to

   Compiling playground v0.0.1 (file:///playground)
error[E0049]: method `foo` has 1 type parameter but its trait declaration has 0 type parameters

error: aborting due to previous error

For more information about this error, try `rustc --explain E0049`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Which is almost completely useless, there aren't even line numbers...

Playground link

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.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