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

Error span is in incorrect place due to Unicode fullwidth characters #45211

Closed
hcpl opened this issue Oct 11, 2017 · 5 comments · Fixed by #45711
Closed

Error span is in incorrect place due to Unicode fullwidth characters #45211

hcpl opened this issue Oct 11, 2017 · 5 comments · Fixed by #45711
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@hcpl
Copy link

hcpl commented Oct 11, 2017

$ rustc +nightly --version
rustc 1.22.0-nightly (d6d711dd8 2017-10-10)
$ uname -sri
Linux 4.2.0-42-generic x86_64

Code:

fn main() {
    let _ = ("こんにちは", 100i40);
}

rustc output:

error: invalid width `40` for integer literal
 --> main.rs:2:23
  |
2 |     let _ = ("こんにちは", 100i40);
  |                       ^^^^^^
  |
  = help: valid widths are 8, 16, 32, 64 and 128

error: aborting due to previous error
@hcpl
Copy link
Author

hcpl commented Oct 11, 2017

GitHub renders fullwidth characters with width less than 2 monospace cells - the span actually starts under the last string char and ends under the 1 digit.

@zackmdavis
Copy link
Member

possibly related to #44080?

@hcpl
Copy link
Author

hcpl commented Oct 11, 2017

@zackmdavis yeah, totally. Also as revealed in #8706 this is likely the same issue which dates back to August 2013.
#21492 seems more appropriate than #8706 according to some comments there - and that should have been fixed by #21499 (as reported here).
Reverted by #24428 (info) => #8706 and #21492 still relevant (silly me, forgot looking at the latest comments in #8706).

Should I close it to decrease the noise/signal ratio or keep it to tell maintainers that this issue is persistent?

@estebank
Copy link
Contributor

Just want to point out that the RLS, which is being distributed with the compiler, transitively depends on unicode-width due to a dependency on clap. I don't remember now if there was decision on avoiding depending on the external unicode-* crates that would allow the compiler to properly account for this. I think part of the discussions predates building rustc with cargo. @alexcrichton, if we don't mind adding that dependency, we can use the existing PRs previously fixing this to solve this once and for all. Thoughts?

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints WG-diagnostics Working group: Diagnostics C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 12, 2017
@alexcrichton
Copy link
Member

Oh certainly, adding a dependency on unicode-width would be totally ok!

bors added a commit that referenced this issue Nov 4, 2017
Display spans correctly when there are zero-width or wide characters

Hopefully...
* fixes #45211
* fixes #8706

---

Before:
```
error: invalid width `7` for integer literal
  --> unicode_2.rs:12:25
   |
12 |     let _ = ("a̐éö̲", 0u7);
   |                         ^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: invalid width `42` for integer literal
  --> unicode_2.rs:13:20
   |
13 |     let _ = ("아あ", 1i42);
   |                    ^^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: aborting due to 2 previous errors
```

After:
```
error: invalid width `7` for integer literal
  --> unicode_2.rs:12:25
   |
12 |     let _ = ("a̐éö̲", 0u7);
   |                     ^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: invalid width `42` for integer literal
  --> unicode_2.rs:13:20
   |
13 |     let _ = ("아あ", 1i42);
   |                      ^^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: aborting due to 2 previous errors
```

Spans might display incorrectly on the browser.

r? @estebank
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants