about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-05-27 03:32:47 +0000
committerbors <bors@rust-lang.org>2018-05-27 03:32:47 +0000
commit1a6bda68cd9d5072f56783f22f7468c19289a020 (patch)
treed07bdbc217214d65ea849c3de07e814e8e27c035 /src/libsyntax/parse
parentf0805a4421449bd6fe3096d63820fbebe2bfcd1d (diff)
parent7dec8a4e99ee10696a3b1e61bfa5918683c49437 (diff)
downloadrust-1a6bda68cd9d5072f56783f22f7468c19289a020.tar.gz
rust-1a6bda68cd9d5072f56783f22f7468c19289a020.zip
Auto merge of #51075 - estebank:and_the_case_of_the_confusable_float_exponent, r=eddyb
Check for confusable Unicode chars in float literal exponent

Fixing tests for #49989. Resolves #49746.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/lexer/mod.rs15
-rw-r--r--src/libsyntax/parse/lexer/unicode_chars.rs10
2 files changed, 18 insertions, 7 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index a9dd234e1ad..c39eb1594b2 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -1075,9 +1075,18 @@ 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)
+                    if unicode_chars::check_for_substitution(self, ch, &mut err) {
+                        self.bump();
+                        self.scan_digits(10, 10);
+                    }
+                }
+                err.emit();
             }
         }
     }
diff --git a/src/libsyntax/parse/lexer/unicode_chars.rs b/src/libsyntax/parse/lexer/unicode_chars.rs
index 35afe8dd56d..c5c2e025233 100644
--- a/src/libsyntax/parse/lexer/unicode_chars.rs
+++ b/src/libsyntax/parse/lexer/unicode_chars.rs
@@ -335,7 +335,7 @@ const ASCII_ARRAY: &'static [(char, &'static str)] = &[
 
 pub fn check_for_substitution<'a>(reader: &StringReader<'a>,
                                   ch: char,
-                                  err: &mut DiagnosticBuilder<'a>) {
+                                  err: &mut DiagnosticBuilder<'a>) -> bool {
     UNICODE_ARRAY
     .iter()
     .find(|&&(c, _, _)| c == ch)
@@ -344,14 +344,16 @@ 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());
+                true
             },
             None => {
                 let msg = format!("substitution character not found for '{}'", ch);
                 reader.sess.span_diagnostic.span_bug_no_panic(span, &msg);
+                false
             }
         }
-    });
+    }).unwrap_or(false)
 }