about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2017-04-05 09:50:04 -0700
committerEsteban Küber <esteban@kuber.com.ar>2017-04-05 09:55:56 -0700
commit44e414c4770ff0800c375ddbb8e0f46ee00bcab1 (patch)
treef6b823912249f4cd632348bc2414c42cb0e8d69c
parent5309a3e31d88def1f3ea966162ed4f81f161d500 (diff)
downloadrust-44e414c4770ff0800c375ddbb8e0f46ee00bcab1.tar.gz
rust-44e414c4770ff0800c375ddbb8e0f46ee00bcab1.zip
Use proper span for tuple index parsed as float
Fix diagnostic suggestion from:

```rust
help: try parenthesizing the first index
  |     (1, (2, 3)).((1, (2, 3)).1).1;
```

to the correct:

```rust
help: try parenthesizing the first index
  |     ((1, (2, 3)).1).1;
```
-rw-r--r--src/libsyntax/parse/parser.rs6
-rw-r--r--src/test/ui/suggestions/tuple-float-index.rs (renamed from src/test/parse-fail/tuple-float-index.rs)4
-rw-r--r--src/test/ui/suggestions/tuple-float-index.stderr11
3 files changed, 15 insertions, 6 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index c2c3e5a6855..0d2c9b92ed7 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2498,10 +2498,10 @@ impl<'a> Parser<'a> {
                   }
                   token::Literal(token::Float(n), _suf) => {
                     self.bump();
-                    let prev_span = self.prev_span;
                     let fstr = n.as_str();
-                    let mut err = self.diagnostic().struct_span_err(prev_span,
+                    let mut err = self.diagnostic().struct_span_err(self.prev_span,
                         &format!("unexpected token: `{}`", n));
+                    err.span_label(self.prev_span, &"unexpected token");
                     if fstr.chars().all(|x| "0123456789.".contains(x)) {
                         let float = match fstr.parse::<f64>().ok() {
                             Some(f) => f,
@@ -2519,7 +2519,7 @@ impl<'a> Parser<'a> {
                             word(&mut s.s, fstr.splitn(2, ".").last().unwrap())
                         });
                         err.span_suggestion(
-                            prev_span,
+                            lo.to(self.prev_span),
                             "try parenthesizing the first index",
                             sugg);
                     }
diff --git a/src/test/parse-fail/tuple-float-index.rs b/src/test/ui/suggestions/tuple-float-index.rs
index 57ad89ad374..8bfbd0e74db 100644
--- a/src/test/parse-fail/tuple-float-index.rs
+++ b/src/test/ui/suggestions/tuple-float-index.rs
@@ -11,7 +11,5 @@
 // compile-flags: -Z parse-only
 
 fn main () {
-    (1, (2, 3)).1.1; //~ ERROR unexpected token
-                     //~^ HELP try parenthesizing the first index
-                     //~| SUGGESTION ((1, (2, 3)).1).1
+    (1, (2, 3)).1.1;
 }
diff --git a/src/test/ui/suggestions/tuple-float-index.stderr b/src/test/ui/suggestions/tuple-float-index.stderr
new file mode 100644
index 00000000000..abe04dc1aa2
--- /dev/null
+++ b/src/test/ui/suggestions/tuple-float-index.stderr
@@ -0,0 +1,11 @@
+error: unexpected token: `1.1`
+  --> $DIR/tuple-float-index.rs:14:17
+   |
+14 |     (1, (2, 3)).1.1;
+   |                 ^^^ unexpected token
+   |
+help: try parenthesizing the first index
+   |     ((1, (2, 3)).1).1;
+
+error: aborting due to previous error
+