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

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

Closed
lukaslueg opened this issue Jul 31, 2018 · 1 comment
Closed

Comments

@lukaslueg
Copy link
Contributor

@lukaslueg 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
@estebank
Copy link
Contributor

@estebank estebank commented Dec 20, 2019

Current output:

error[E0049]: method `foo` has 1 type parameter but its trait declaration has 0 type parameters
  --> src/main.rs:12:25
   |
2  |     fn foo(&self, i32) {}
   |           - expected 0 type parameters
...
12 |     fn foo(&self, bar: &impl FooTrait) {}
   |                         ^^^^^^^^^^^^^
   |                         |
   |                         found 1 type parameter
   |                         `impl Trait` introduces an implicit type parameter

error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters
  --> src/main.rs:13:25
   |
3  |     fn bar(&self, i32) {}
   |           - expected 0 type parameters
...
13 |     fn bar(&self, bar: &impl FooTrait) {}
   |                         ^^^^^^^^^^^^^
   |                         |
   |                         found 1 type parameter
   |                         `impl Trait` introduces an implicit type parameter

error: aborting due to 2 previous errors
@estebank estebank closed this Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants