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

Be explicit when spans are overlapping in error message #37453

Closed
estebank opened this issue Oct 28, 2016 · 1 comment
Closed

Be explicit when spans are overlapping in error message #37453

estebank opened this issue Oct 28, 2016 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@estebank
Copy link
Contributor

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
@sanxiyn sanxiyn added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 29, 2016
@estebank
Copy link
Contributor Author

Will be fixed when PR #37369 gets merged.

estebank added a commit to estebank/rust that referenced this issue Dec 15, 2016
After the fix of rust-lang#37453 in PR rust-lang#37369, instead of pointing at only the
cast type, point at the full cast span when a cast needs a dereference:

```
error: casting `&{float}` as `f32` is invalid
  --> ../../../src/test/ui/mismatched_types/cast-rfc0401.rs:81:30
   |
81 |     vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>();
   |                              ^^^^^^^^ cannot cast `&{float}` as `f32`
   |
help: did you mean `*s`?
  --> ../../../src/test/ui/mismatched_types/cast-rfc0401.rs:81:30
   |
81 |     vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>();
   |                              ^
```

instead of

```
error: casting `&{float}` as `f32` is invalid
  --> ../../../src/test/ui/mismatched_types/cast-rfc0401.rs:81:35
   |
81 |     vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>();
   |                              -    ^^^
   |                              |
   |                              |
   |                              did you mean `*s`?
   |                              cannot cast `&{float}` as `f32`
```
bors added a commit that referenced this issue Dec 20, 2016
When cast needs a dereference point at full cast

After the fix of #37453 in PR #37369, instead of pointing at only the cast type, point at the full cast span when a cast needs a dereference, as well as assign the error label to the correct span for proper coloring:

<img width="471" alt="error span pointing at the entire cast" src="https://cloud.githubusercontent.com/assets/1606434/21024245/8797fc2e-bd38-11e6-82c1-66c281c656c1.png">

instead of

<img width="471" alt="error span pointing at the type of the cast" src="https://cloud.githubusercontent.com/assets/1606434/21023777/d4814aa6-bd36-11e6-9fc3-b2a0ea5ee15d.png">

Move `compile-fail` test to `ui` test.
alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 20, 2016
…atsakis

When cast needs a dereference point at full cast

After the fix of rust-lang#37453 in PR rust-lang#37369, instead of pointing at only the cast type, point at the full cast span when a cast needs a dereference, as well as assign the error label to the correct span for proper coloring:

<img width="471" alt="error span pointing at the entire cast" src="https://cloud.githubusercontent.com/assets/1606434/21024245/8797fc2e-bd38-11e6-82c1-66c281c656c1.png">

instead of

<img width="471" alt="error span pointing at the type of the cast" src="https://cloud.githubusercontent.com/assets/1606434/21023777/d4814aa6-bd36-11e6-9fc3-b2a0ea5ee15d.png">

Move `compile-fail` test to `ui` test.
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

2 participants