Skip to content

Commit 8d1cc72

Browse files
committed
Add specific message for tuple struct invoked with suffixed numeric field name
1 parent 1bb3694 commit 8d1cc72

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/libsyntax/parse/parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,8 @@ impl<'a> Parser<'a> {
24912491
}
24922492

24932493
fn parse_field_name(&mut self) -> PResult<'a, Ident> {
2494-
if let token::Literal(token::Integer(name), None) = self.token {
2494+
if let token::Literal(token::Integer(name), suffix) = self.token {
2495+
self.expect_no_suffix(self.span, "a tuple index", suffix);
24952496
self.bump();
24962497
Ok(Ident::new(name, self.prev_span))
24972498
} else {

src/test/ui/parser/issue-59418.rs

+6
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ fn main() {
99
let d = c.1suffix;
1010
//~^ ERROR suffixes on a tuple index are invalid
1111
println!("{}", d);
12+
let s = X { 0suffix: 0, 1: 1, 2: 2 };
13+
//~^ ERROR suffixes on a tuple index are invalid
14+
match s {
15+
X { 0suffix: _, .. } => {}
16+
//~^ ERROR suffixes on a tuple index are invalid
17+
}
1218
}

src/test/ui/parser/issue-59418.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,17 @@ error: suffixes on a tuple index are invalid
1010
LL | let d = c.1suffix;
1111
| ^^^^^^^ invalid suffix `suffix`
1212

13-
error: aborting due to 2 previous errors
13+
error: suffixes on a tuple index are invalid
14+
--> $DIR/issue-59418.rs:12:17
15+
|
16+
LL | let s = X { 0suffix: 0, 1: 1, 2: 2 };
17+
| ^^^^^^^ invalid suffix `suffix`
18+
19+
error: suffixes on a tuple index are invalid
20+
--> $DIR/issue-59418.rs:15:13
21+
|
22+
LL | X { 0suffix: _, .. } => {}
23+
| ^^^^^^^ invalid suffix `suffix`
24+
25+
error: aborting due to 4 previous errors
1426

0 commit comments

Comments
 (0)