From 7ac124803f696b7e28d9fdae2f676093024de378 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 7 Sep 2022 03:59:47 +0900 Subject: [PATCH] do not suggest a semicolon for a macro without `!` --- compiler/rustc_parse/src/parser/expr.rs | 3 +++ ...-array.rs => do-not-suggest-semicolon-before-array.rs} | 0 ...tderr => do-not-suggest-semicolon-before-array.stderr} | 2 +- ...on-between-macro-without-exclamation-mark-and-array.rs | 3 +++ ...etween-macro-without-exclamation-mark-and-array.stderr | 8 ++++++++ ...e-array.fixed => suggest-semicolon-before-array.fixed} | 0 ...-before-array.rs => suggest-semicolon-before-array.rs} | 0 ...array.stderr => suggest-semicolon-before-array.stderr} | 2 +- 8 files changed, 16 insertions(+), 2 deletions(-) rename src/test/ui/parser/{do-not-suggest-suggest-semicolon-before-array.rs => do-not-suggest-semicolon-before-array.rs} (100%) rename src/test/ui/parser/{do-not-suggest-suggest-semicolon-before-array.stderr => do-not-suggest-semicolon-before-array.stderr} (76%) create mode 100644 src/test/ui/parser/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.rs create mode 100644 src/test/ui/parser/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.stderr rename src/test/ui/parser/{suggest-suggest-semicolon-before-array.fixed => suggest-semicolon-before-array.fixed} (100%) rename src/test/ui/parser/{suggest-suggest-semicolon-before-array.rs => suggest-semicolon-before-array.rs} (100%) rename src/test/ui/parser/{suggest-suggest-semicolon-before-array.stderr => suggest-semicolon-before-array.stderr} (75%) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index d4828a20120..10cd353062e 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1977,6 +1977,9 @@ fn suggest_missing_semicolon_before_array( 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)) { + return Ok(()); + } let mut snapshot = self.create_snapshot_for_diagnostic(); snapshot.bump(); match snapshot.parse_seq_to_before_end( diff --git a/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.rs b/src/test/ui/parser/do-not-suggest-semicolon-before-array.rs similarity index 100% rename from src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.rs rename to src/test/ui/parser/do-not-suggest-semicolon-before-array.rs diff --git a/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.stderr b/src/test/ui/parser/do-not-suggest-semicolon-before-array.stderr similarity index 76% rename from src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.stderr rename to src/test/ui/parser/do-not-suggest-semicolon-before-array.stderr index d6e8db80329..a9dd526321f 100644 --- a/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.stderr +++ b/src/test/ui/parser/do-not-suggest-semicolon-before-array.stderr @@ -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 diff --git a/src/test/ui/parser/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.rs b/src/test/ui/parser/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.rs new file mode 100644 index 00000000000..d6f7981813f --- /dev/null +++ b/src/test/ui/parser/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.rs @@ -0,0 +1,3 @@ +fn main() { + let _x = vec[1, 2, 3]; //~ ERROR expected one of `.`, `?`, `]`, or an operator +} diff --git a/src/test/ui/parser/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.stderr b/src/test/ui/parser/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.stderr new file mode 100644 index 00000000000..2fe6a28eeb4 --- /dev/null +++ b/src/test/ui/parser/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.stderr @@ -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 + diff --git a/src/test/ui/parser/suggest-suggest-semicolon-before-array.fixed b/src/test/ui/parser/suggest-semicolon-before-array.fixed similarity index 100% rename from src/test/ui/parser/suggest-suggest-semicolon-before-array.fixed rename to src/test/ui/parser/suggest-semicolon-before-array.fixed diff --git a/src/test/ui/parser/suggest-suggest-semicolon-before-array.rs b/src/test/ui/parser/suggest-semicolon-before-array.rs similarity index 100% rename from src/test/ui/parser/suggest-suggest-semicolon-before-array.rs rename to src/test/ui/parser/suggest-semicolon-before-array.rs diff --git a/src/test/ui/parser/suggest-suggest-semicolon-before-array.stderr b/src/test/ui/parser/suggest-semicolon-before-array.stderr similarity index 75% rename from src/test/ui/parser/suggest-suggest-semicolon-before-array.stderr rename to src/test/ui/parser/suggest-semicolon-before-array.stderr index bf86b43554d..8a33321fbd5 100644 --- a/src/test/ui/parser/suggest-suggest-semicolon-before-array.stderr +++ b/src/test/ui/parser/suggest-semicolon-before-array.stderr @@ -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] | ^