diff options
| author | bors <bors@rust-lang.org> | 2023-11-28 02:05:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-28 02:05:26 +0000 |
| commit | c2ec90854a0d3a3e1570cf7acfdd2c9e50aa3b2a (patch) | |
| tree | 5fc9b9c573cad226f388cefb957c03983923675d /compiler/rustc_parse/src/parser | |
| parent | 49b3924bd4a34d3cf9c37b74120fba78d9712ab8 (diff) | |
| parent | 2aca7247a7c63d43510ac136c5e26c8ddfd40180 (diff) | |
| download | rust-c2ec90854a0d3a3e1570cf7acfdd2c9e50aa3b2a.tar.gz rust-c2ec90854a0d3a3e1570cf7acfdd2c9e50aa3b2a.zip | |
Auto merge of #118395 - compiler-errors:rollup-c8yqlmw, r=compiler-errors
Rollup of 9 pull requests Successful merges: - #111133 (Detect Python-like slicing and suggest how to fix) - #114708 (Allow setting `rla` labels via `rustbot`) - #117526 (Account for `!` arm in tail `match` expr) - #118172 (Add `pretty_terminator` to pretty stable-mir) - #118202 (Added linker_arg(s) Linker trait methods for link-arg to be prefixed "-Wl," for cc-like linker args and not verbatim) - #118374 (QueryContext: rename try_collect_active_jobs -> collect_active_jobs, change return type from Option<QueryMap> to QueryMap) - #118381 (rustc_span: Use correct edit distance start length for suggestions) - #118382 (Address unused tuple struct fields in the compiler) - #118384 (Address unused tuple struct fields in rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 5316dde6096..620ba4a3cb3 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -567,20 +567,37 @@ impl<'a> Parser<'a> { snapshot.recover_diff_marker(); } if self.token == token::Colon { - // 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() { + // if a previous and next token of the current one is + // 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 + // this only when parsing an index expression. err.span_suggestion_verbose( - self.prev_token.span, - "maybe write a path separator here", - "::", + self.token.span, + "you might have meant a range expression", + "..", 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>"); + } } } |
