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
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@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
@cramertj cramertj added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 31, 2018
@oli-obk oli-obk added the A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. label Aug 1, 2018
@JohnTitor JohnTitor added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 19, 2019
@estebank
Copy link
Contributor

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

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-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants