Skip to content

Be explicit when spans are overlapping in error message #37453

Closed
@estebank

Description

@estebank

When working on PR #37442, I ended up with the following output:

error: casting `&f64` as `i16` is invalid
 --> file3.rs:2:30
  |
2 |     vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();
  |                              ^^^^^^^^      // <<< this in red
  |                              |             // <<< this in red
  |                              casting `&f64` as `i16` is invalid      // <<< this in red
  |                              try dereferencing for the cast to work  // <<< this in blue

The second span label points at the first character of the span, but because there's already a larger span there, the actual extent of that span is lost.

I believe that either the shortest span should be shown within the existing span:

2 |     vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();
  |                              -^^^^^^^
  |                              |
  |                              casting `&f64` as `i16` is invalid
  |                              try dereferencing for the cast to work

there should be a new character introduced for when multiple labels overlap:

2 |     vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();
  |                              ~^^^^^^^
  |                              |
  |                              casting `&f64` as `i16` is invalid
  |                              try dereferencing for the cast to work

or at the very least, colorize the smaller span with the secondary label's color:

2 |     vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();
  |                              ^^^^^^^^     // <<< first character should be blue
  |                              |
  |                              casting `&f64` as `i16` is invalid
  |                              try dereferencing for the cast to work

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