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

Unicode minus sign error message in literals #49746

Closed
sunjay opened this issue Apr 6, 2018 · 1 comment
Closed

Unicode minus sign error message in literals #49746

sunjay opened this issue Apr 6, 2018 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@sunjay
Copy link
Member

sunjay commented Apr 6, 2018

This code: (Playground Link)

fn main() {
    let x: f64 = 6.674e−11;
}

Looks pretty identical to this code:

fn main() {
    let x: f64 = 6.674e-11;
}

But the first one doesn't compile because I accidentally used a unicode minus sign (−) instead of a dash (-). This happened to me when I pasted a constant from Wikipedia.

error: expected at least one digit in exponent
 --> src/main.rs:2:24
  |
2 |     let x: f64 = 6.674e−11;
  |                        ^

We already produce an error about things like this in other cases. For example with an en space:

fn main() {
    let a = ();
}

We produce the following:

error: unknown start of token: \u{2002}
 --> src/main.rs:2:8
  |
2 |     let a = ();
  |        ^
  |
help: unicode character ' ' (En Space) looks like ' ' (Space), but it's not
 --> src/main.rs:2:8
  |
2 |     let a = ();
  |        ^

error: Could not compile `playground`.

Maybe we could do the same for the minus sign since it is a pretty confusing error to receive?

@sfackler sfackler added the A-diagnostics Area: Messages for errors, warnings, and lints label Apr 6, 2018
@Badel2
Copy link
Contributor

Badel2 commented Apr 7, 2018

The unicode minus sign is already on the list of similar characters:

('−', "Minus Sign", '-'),

However it looks like it doesn't work in this context.

zackmdavis added a commit to zackmdavis/rust that referenced this issue Apr 15, 2018
The `FatalError.raise()` might seem unmotivated (in most places in
the compiler, `err.emit()` suffices), but it's actually used to
maintain behavior (viz., stop lexing, don't emit potentially spurious
errors looking for the next token after the bad Unicodepoint in the
exponent): the previous revision's `self.err_span_` ultimately calls
`Handler::emit`, which aborts if the `Handler`'s continue_after_error
flag is set, which seems to typically be true during lexing (see
`phase_1_parse_input` and and how `CompileController::basic` has
`continue_parse_after_error: false` in librustc_driver).

Also, let's avoid apostrophes in error messages (the present author
would argue that users expect a reassuringly detached, formal,
above-it-all tone from a Serious tool like a compiler), and use an
RLS-friendly structured suggestion.

Resolves rust-lang#49746.
estebank pushed a commit to estebank/rust that referenced this issue May 26, 2018
The `FatalError.raise()` might seem unmotivated (in most places in
the compiler, `err.emit()` suffices), but it's actually used to
maintain behavior (viz., stop lexing, don't emit potentially spurious
errors looking for the next token after the bad Unicodepoint in the
exponent): the previous revision's `self.err_span_` ultimately calls
`Handler::emit`, which aborts if the `Handler`'s continue_after_error
flag is set, which seems to typically be true during lexing (see
`phase_1_parse_input` and and how `CompileController::basic` has
`continue_parse_after_error: false` in librustc_driver).

Also, let's avoid apostrophes in error messages (the present author
would argue that users expect a reassuringly detached, formal,
above-it-all tone from a Serious tool like a compiler), and use an
RLS-friendly structured suggestion.

Resolves rust-lang#49746.
bors added a commit that referenced this issue May 27, 2018
…exponent, r=eddyb

Check for confusable Unicode chars in float literal exponent

Fixing tests for #49989. Resolves #49746.
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

3 participants