Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not suggest a semicolon for a macro without ! #101502

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,9 @@ impl<'a> Parser<'a> {
open_delim_span: Span,
) -> PResult<'a, ()> {
if self.token.kind == token::Comma {
if !self.sess.source_map().is_multiline(prev_span.until(self.token.span)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refers to Parser::expected_one_of_not_found.

} else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
// The current token is in the same line as the prior token, not recoverable.

return Ok(());
}
let mut snapshot = self.create_snapshot_for_diagnostic();
snapshot.bump();
match snapshot.parse_seq_to_before_end(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: expected one of `.`, `?`, `]`, or an operator, found `,`
--> $DIR/do-not-suggest-suggest-semicolon-before-array.rs:5:5
--> $DIR/do-not-suggest-semicolon-before-array.rs:5:5
|
LL | [1, 3)
| ^ ^ help: `]` may belong here
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let _x = vec[1, 2, 3]; //~ ERROR expected one of `.`, `?`, `]`, or an operator
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: expected one of `.`, `?`, `]`, or an operator, found `,`
--> $DIR/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.rs:2:19
|
LL | let _x = vec[1, 2, 3];
| ^ expected one of `.`, `?`, `]`, or an operator

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: expected `;`, found `[`
--> $DIR/suggest-suggest-semicolon-before-array.rs:8:5
--> $DIR/suggest-semicolon-before-array.rs:8:5
|
LL | [1, 3]
| ^
Expand Down