Skip to content

in which we check for confusable Unicodepoints in float literal exponent #49989

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,16 @@ impl<'a> StringReader<'a> {
self.bump();
}
if self.scan_digits(10, 10) == 0 {
self.err_span_(self.pos,
self.next_pos,
"expected at least one digit in exponent")
let mut err = self.struct_span_fatal(
self.pos, self.next_pos,
"expected at least one digit in exponent"
);
if let Some(ch) = self.ch {
// check for e.g. Unicode minus '−' (Issue #49746)
unicode_chars::check_for_substitution(self, ch, &mut err);
}
err.emit();
FatalError.raise();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/parse/lexer/unicode_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ pub fn check_for_substitution<'a>(reader: &StringReader<'a>,
match ASCII_ARRAY.iter().find(|&&(c, _)| c == ascii_char) {
Some(&(ascii_char, ascii_name)) => {
let msg =
format!("unicode character '{}' ({}) looks like '{}' ({}), but it's not",
format!("Unicode character '{}' ({}) looks like '{}' ({}), but it is not",
ch, u_name, ascii_char, ascii_name);
err.span_help(span, &msg);
err.span_suggestion(span, &msg, ascii_char.to_string());
},
None => {
let msg = format!("substitution character not found for '{}'", ch);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

const UNIVERSAL_GRAVITATIONAL_CONSTANT = 6.674e−11; // m³⋅kg⁻¹⋅s⁻²
//~^ ERROR expected at least one digit in exponent

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error: expected at least one digit in exponent
--> $DIR/issue-49746-unicode-confusable-in-float-literal-expt.rs:11:48
|
LL | const UNIVERSAL_GRAVITATIONAL_CONSTANT = 6.674e−11; // m³⋅kg⁻¹⋅s⁻²
| ^
help: Unicode character '−' (Minus Sign) looks like '-' (Minus/Hyphen), but it is not
|
LL | const UNIVERSAL_GRAVITATIONAL_CONSTANT = 6.674e-11; // m³⋅kg⁻¹⋅s⁻²
| ^

error: aborting due to previous error