Skip to content

Bad span when complaining about trait implementation not having the right number of parameters #56582

Description

@RalfJung

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.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    on Dec 7, 2018
  2. added a commit that references this issue on Dec 10, 2018
    b37ad66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lints

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions