Skip to content

E0053 needs tighter spans #35212

Closed
Closed
@sophiajt

Description

@sophiajt

From: src/test/compile-fail/E0053.rs

Some bonus tasks on this one:

  • Add the original trait requirement, so that you can see both the error and what the original trait expects
  • If possible, tighten the spans

Error E0053 currently is updated to the new error format, but the spans are very large. Ideally, instead of this:

error[E0053]: method `foo` has an incompatible type for trait
  --> src/test/compile-fail/E0053.rs:19:5
   |
19 |     fn foo(x: i16) { } //~ ERROR E0053
   |     ^^^^^^^^^^^^^^^^^^ expected u16, found i16

error[E0053]: method `bar` has an incompatible type for trait
  --> src/test/compile-fail/E0053.rs:20:5
   |
20 |     fn bar(&mut self) { } //~ ERROR E0053
   |     ^^^^^^^^^^^^^^^^^^^^^ values differ in mutability
   |
   = note: expected type `fn(&Bar)`
   = note:    found type `fn(&mut Bar)`

We could have smaller spans (with updated labels):

error[E0053]: method `foo` has an incompatible type for trait
  --> src/test/compile-fail/E0053.rs:19:5
   |
19 |     fn foo(x: i16) { } //~ ERROR E0053
   |               ^^^ expected u16

error[E0053]: method `bar` has an incompatible type for trait
  --> src/test/compile-fail/E0053.rs:20:5
   |
20 |     fn bar(&mut self) { } //~ ERROR E0053
   |            ^^^^ values differ in mutability
   |
   = note: expected type `fn(&Bar)`
   = note:    found type `fn(&mut Bar)`

It would also be great to show what the other definition was:

error[E0053]: method `foo` has an incompatible type for trait
  --> src/test/compile-fail/E0053.rs:19:5
   |
12 |     fn foo(x: u16);
   |               --- original trait requirement
...
19 |     fn foo(x: i16) { } //~ ERROR E0053
   |               ^^^ expected u16

error[E0053]: method `bar` has an incompatible type for trait
  --> src/test/compile-fail/E0053.rs:20:5
   |
13 |     fn bar(&self);
   |            - original trait requirement
...
20 |     fn bar(&mut self) { } //~ ERROR E0053
   |            ^^^^ values differ in mutability
   |
   = note: expected type `fn(&Bar)`
   = note:    found type `fn(&mut Bar)`

Metadata

Metadata

Assignees

No one assigned

    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