Skip to content

Commit

Permalink
Address review feedbacks
Browse files Browse the repository at this point in the history
Also addressed merge conflicts upon rebasing.
  • Loading branch information
hkmatsumoto committed May 16, 2023
1 parent c32ea0a commit b8e582e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
33 changes: 17 additions & 16 deletions compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/101728>");
}
}
}

Expand Down
1 change: 0 additions & 1 deletion tests/ui/suggestions/range-index-instead-of-colon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 0 additions & 5 deletions tests/ui/suggestions/range-index-instead-of-colon.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/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

0 comments on commit b8e582e

Please sign in to comment.