From b8e582e8344b8dafdfc3688a7b80a0f8f36c86fe Mon Sep 17 00:00:00 2001 From: Hirochika Matsumoto Date: Tue, 16 May 2023 14:53:05 +0900 Subject: [PATCH] Address review feedbacks Also addressed merge conflicts upon rebasing. --- compiler/rustc_parse/src/parser/stmt.rs | 33 ++++++++++--------- .../range-index-instead-of-colon.rs | 1 - .../range-index-instead-of-colon.stderr | 5 --- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 529e5d9168a0f..4af3717a58d4c 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -567,6 +567,7 @@ impl<'a> Parser<'a> { // integer literal (e.g. `1:42`), it's likely a range // expression for Pythonistas and we can suggest so. if self.prev_token.is_integer_lit() + && self.may_recover() && self.look_ahead(1, |token| token.is_integer_lit()) { // FIXME(hkmatsumoto): Might be better to trigger @@ -577,22 +578,22 @@ impl<'a> Parser<'a> { "..", Applicability::MaybeIncorrect, ); - } - - // if next token is following a colon, it's likely a path - // and we can suggest a path separator - self.bump(); - if self.token.span.lo() == self.prev_token.span.hi() { - err.span_suggestion_verbose( - self.prev_token.span, - "maybe write a path separator here", - "::", - Applicability::MaybeIncorrect, - ); - } - if self.sess.unstable_features.is_nightly_build() { - // FIXME(Nilstrieb): Remove this again after a few months. - err.note("type ascription syntax has been removed, see issue #101728 "); + } else { + // if next token is following a colon, it's likely a path + // and we can suggest a path separator + self.bump(); + if self.token.span.lo() == self.prev_token.span.hi() { + err.span_suggestion_verbose( + self.prev_token.span, + "maybe write a path separator here", + "::", + Applicability::MaybeIncorrect, + ); + } + if self.sess.unstable_features.is_nightly_build() { + // FIXME(Nilstrieb): Remove this again after a few months. + err.note("type ascription syntax has been removed, see issue #101728 "); + } } } diff --git a/tests/ui/suggestions/range-index-instead-of-colon.rs b/tests/ui/suggestions/range-index-instead-of-colon.rs index f183590d2c7a2..0805102de7844 100644 --- a/tests/ui/suggestions/range-index-instead-of-colon.rs +++ b/tests/ui/suggestions/range-index-instead-of-colon.rs @@ -4,5 +4,4 @@ fn main() { &[1, 2, 3][1:2]; //~^ ERROR: expected one of //~| HELP: you might have meant to make a slice with range index - //~| HELP: maybe write a path separator here } diff --git a/tests/ui/suggestions/range-index-instead-of-colon.stderr b/tests/ui/suggestions/range-index-instead-of-colon.stderr index 72e400fba0ac8..f1714e5598bd1 100644 --- a/tests/ui/suggestions/range-index-instead-of-colon.stderr +++ b/tests/ui/suggestions/range-index-instead-of-colon.stderr @@ -4,15 +4,10 @@ error: expected one of `.`, `?`, `]`, or an operator, found `:` LL | &[1, 2, 3][1:2]; | ^ expected one of `.`, `?`, `]`, or an operator | - = note: type ascription syntax has been removed, see issue #101728 help: you might have meant to make a slice with range index | LL | &[1, 2, 3][1..2]; | ~~ -help: maybe write a path separator here - | -LL | &[1, 2, 3][1::2]; - | ~~ error: aborting due to previous error