Skip to content

Commit 918e35a

Browse files
authored
Rollup merge of rust-lang#41087 - estebank:tuple-float-index, r=arielb1
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; ``` Fix rust-lang#41081.
2 parents 49082ae + 44e414c commit 918e35a

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
@@ -2552,10 +2552,10 @@ impl<'a> Parser<'a> {
25522552
}
25532553
token::Literal(token::Float(n), _suf) => {
25542554
self.bump();
2555-
let prev_span = self.prev_span;
25562555
let fstr = n.as_str();
2557-
let mut err = self.diagnostic().struct_span_err(prev_span,
2556+
let mut err = self.diagnostic().struct_span_err(self.prev_span,
25582557
&format!("unexpected token: `{}`", n));
2558+
err.span_label(self.prev_span, &"unexpected token");
25592559
if fstr.chars().all(|x| "0123456789.".contains(x)) {
25602560
let float = match fstr.parse::<f64>().ok() {
25612561
Some(f) => f,
@@ -2573,7 +2573,7 @@ impl<'a> Parser<'a> {
25732573
word(&mut s.s, fstr.splitn(2, ".").last().unwrap())
25742574
});
25752575
err.span_suggestion(
2576-
prev_span,
2576+
lo.to(self.prev_span),
25772577
"try parenthesizing the first index",
25782578
sugg);
25792579
}

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)