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 span when complaining about trait implementation not having the right number of parameters #56582

Closed
RalfJung opened this issue Dec 7, 2018 · 0 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@RalfJung
Copy link
Member

RalfJung commented Dec 7, 2018

This code

trait Foo {
    fn foo(&mut self, x: i32, y: i32) -> i32;
}

impl Foo for i32 {
    fn foo(
        &mut self,
        x: i32
    ) {
        
    }
}

shows the error

error[E0050]: method `foo` has 2 parameters but the declaration in trait `Foo::foo` has 3
 --> src/lib.rs:8:12
  |
2 |     fn foo(&mut self, x: i32, y: i32) -> i32;
  |                                  --- trait requires 3 parameters
...
8 |         x: i32
  |            ^^^ expected 3 parameters, found 2

error: aborting due to previous error

It is rather odd that it points at the type of the last parameter. In particular when there is just one parameter per line, this span is not helpful.

The span should probably encompass all parameters.

@csmoe csmoe added the A-diagnostics Area: Messages for errors, warnings, and lints label Dec 7, 2018
@GuillaumeGomez GuillaumeGomez self-assigned this Dec 8, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 10, 2018
…valid-nb-parameters, r=estebank

fix span for invalid number of parameters in trait method

Fixes rust-lang#56582.
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
Projects
None yet
Development

No branches or pull requests

3 participants