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

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

Open
lukaslueg opened this Issue Jul 31, 2018 · 0 comments

Comments

Projects
None yet
3 participants
@lukaslueg
Copy link
Contributor

lukaslueg commented Jul 31, 2018

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

@lukaslueg lukaslueg changed the title Bad error message with `impl trait`-parameter on trait implementation Bad error message with wrong `impl trait`-parameter on trait implementation Jul 31, 2018

@oli-obk oli-obk added the A-impl-trait label Aug 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment