Skip to content

Unicode minus sign error message in literals #49746

Closed
@sunjay

Description

@sunjay

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?

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