Skip to content

Commit 9d5c74e

Browse files
Do not suggest adding ; when , is also a choice
1 parent e55c53c commit 9d5c74e

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ impl<'a> Parser<'a> {
560560
|| (sm.is_multiline(
561561
self.prev_token.span.shrink_to_hi().until(self.token.span.shrink_to_lo())
562562
) && t == &token::Pound)
563-
}) {
563+
}) && !expected.contains(&TokenType::Token(token::Comma))
564+
{
564565
// Missing semicolon typo. This is triggered if the next token could either start a
565566
// new statement or is a block close. For example:
566567
//

src/test/ui/parser/issues/issue-88770.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// error-pattern:this file contains an unclosed delimiter
44
// error-pattern:expected one of
55
// error-pattern:missing `in` in `for` loop
6-
// error-pattern:expected `;`, found `e`
6+
// error-pattern:expected one of `!`, `)`, `,`, `.`, `::`, `;`, `?`, `{`, or an operator, found `e`
77

88
fn m(){print!("",(c for&g
99
u

src/test/ui/parser/issues/issue-88770.stderr

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,13 @@ error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found
4848
LL | fn m(){print!("",(c for&g
4949
| ^^^ expected one of 8 possible tokens
5050

51-
error: expected `;`, found `e`
52-
--> $DIR/issue-88770.rs:10:2
51+
error: expected one of `!`, `)`, `,`, `.`, `::`, `;`, `?`, `{`, or an operator, found `e`
52+
--> $DIR/issue-88770.rs:11:1
5353
|
5454
LL | e
55-
| ^ help: add `;` here
55+
| - expected one of 9 possible tokens
5656
LL | e
57-
| - unexpected token
57+
| ^ unexpected token
5858

59-
error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `)`
60-
--> $DIR/issue-88770.rs:11:3
61-
|
62-
LL | e
63-
| ^ expected one of 7 possible tokens
64-
65-
error: aborting due to 7 previous errors
59+
error: aborting due to 6 previous errors
6660

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
let v = [1
3+
2];
4+
//~^ ERROR expected one of `,`, `.`, `;`, `?`, `]`, or an operator, found `2`
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected one of `,`, `.`, `;`, `?`, `]`, or an operator, found `2`
2+
--> $DIR/suggest-semi-in-array.rs:3:5
3+
|
4+
LL | let v = [1
5+
| - expected one of `,`, `.`, `;`, `?`, `]`, or an operator
6+
LL | 2];
7+
| ^ unexpected token
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)