Skip to content

Commit 730d299

Browse files
committed
Address review feedbacks
Also addressed merge conflicts upon rebasing.
1 parent 61c3e4d commit 730d299

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

compiler/rustc_parse/src/parser/stmt.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ impl<'a> Parser<'a> {
571571
// integer literal (e.g. `1:42`), it's likely a range
572572
// expression for Pythonistas and we can suggest so.
573573
if self.prev_token.is_integer_lit()
574+
&& self.may_recover()
574575
&& self.look_ahead(1, |token| token.is_integer_lit())
575576
{
576577
// FIXME(hkmatsumoto): Might be better to trigger
@@ -581,22 +582,22 @@ impl<'a> Parser<'a> {
581582
"..",
582583
Applicability::MaybeIncorrect,
583584
);
584-
}
585-
586-
// if next token is following a colon, it's likely a path
587-
// and we can suggest a path separator
588-
self.bump();
589-
if self.token.span.lo() == self.prev_token.span.hi() {
590-
err.span_suggestion_verbose(
591-
self.prev_token.span,
592-
"maybe write a path separator here",
593-
"::",
594-
Applicability::MaybeIncorrect,
595-
);
596-
}
597-
if self.sess.unstable_features.is_nightly_build() {
598-
// FIXME(Nilstrieb): Remove this again after a few months.
599-
err.note("type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>");
585+
} else {
586+
// if next token is following a colon, it's likely a path
587+
// and we can suggest a path separator
588+
self.bump();
589+
if self.token.span.lo() == self.prev_token.span.hi() {
590+
err.span_suggestion_verbose(
591+
self.prev_token.span,
592+
"maybe write a path separator here",
593+
"::",
594+
Applicability::MaybeIncorrect,
595+
);
596+
}
597+
if self.sess.unstable_features.is_nightly_build() {
598+
// FIXME(Nilstrieb): Remove this again after a few months.
599+
err.note("type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>");
600+
}
600601
}
601602
}
602603

tests/ui/suggestions/range-index-instead-of-colon.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ fn main() {
44
&[1, 2, 3][1:2];
55
//~^ ERROR: expected one of
66
//~| HELP: you might have meant to make a slice with range index
7-
//~| HELP: maybe write a path separator here
87
}

tests/ui/suggestions/range-index-instead-of-colon.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ error: expected one of `.`, `?`, `]`, or an operator, found `:`
44
LL | &[1, 2, 3][1:2];
55
| ^ expected one of `.`, `?`, `]`, or an operator
66
|
7-
= note: type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
87
help: you might have meant to make a slice with range index
98
|
109
LL | &[1, 2, 3][1..2];
1110
| ~~
12-
help: maybe write a path separator here
13-
|
14-
LL | &[1, 2, 3][1::2];
15-
| ~~
1611

17-
error: aborting due to previous error
12+
error: aborting due to 1 previous error
1813

0 commit comments

Comments
 (0)