Skip to content

Commit 44e414c

Browse files
committed
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; ```
1 parent 5309a3e commit 44e414c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/libsyntax/parse/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2498,10 +2498,10 @@ impl<'a> Parser<'a> {
24982498
}
24992499
token::Literal(token::Float(n), _suf) => {
25002500
self.bump();
2501-
let prev_span = self.prev_span;
25022501
let fstr = n.as_str();
2503-
let mut err = self.diagnostic().struct_span_err(prev_span,
2502+
let mut err = self.diagnostic().struct_span_err(self.prev_span,
25042503
&format!("unexpected token: `{}`", n));
2504+
err.span_label(self.prev_span, &"unexpected token");
25052505
if fstr.chars().all(|x| "0123456789.".contains(x)) {
25062506
let float = match fstr.parse::<f64>().ok() {
25072507
Some(f) => f,
@@ -2519,7 +2519,7 @@ impl<'a> Parser<'a> {
25192519
word(&mut s.s, fstr.splitn(2, ".").last().unwrap())
25202520
});
25212521
err.span_suggestion(
2522-
prev_span,
2522+
lo.to(self.prev_span),
25232523
"try parenthesizing the first index",
25242524
sugg);
25252525
}

src/test/parse-fail/tuple-float-index.rs renamed to src/test/ui/suggestions/tuple-float-index.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@
1111
// compile-flags: -Z parse-only
1212

1313
fn main () {
14-
(1, (2, 3)).1.1; //~ ERROR unexpected token
15-
//~^ HELP try parenthesizing the first index
16-
//~| SUGGESTION ((1, (2, 3)).1).1
14+
(1, (2, 3)).1.1;
1715
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: unexpected token: `1.1`
2+
--> $DIR/tuple-float-index.rs:14:17
3+
|
4+
14 | (1, (2, 3)).1.1;
5+
| ^^^ unexpected token
6+
|
7+
help: try parenthesizing the first index
8+
| ((1, (2, 3)).1).1;
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)