Recover and suggest to use ; to construct array type#143905
Recover and suggest to use ; to construct array type#143905bors merged 2 commits intorust-lang:masterfrom
; to construct array type#143905Conversation
| help: use `=` if you meant to assign | ||
| | | ||
| LL - let b: [i32, 5]; | ||
| LL + let b = [i32, 5]; |
There was a problem hiding this comment.
This suggestion is wrong, but it have nothing with this PR. Because the old diagnostic has the same help message.
Old Diagnostic:
error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `]`, found `,`
--> src/main.rs:3:16
|
3 | let b: [i32, 5];
| - ^ expected one of 7 possible tokens
| |
| while parsing the type for `b`
| help: use `=` if you meant to assign
|
r? compiler-errors @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
Yeah, I have tried to recover it to https://github.com/rust-lang/rust/blob/master/tests/ui/issues/issue-50571.rs @rustbot ready |
compiler-errors
left a comment
There was a problem hiding this comment.
I personally think it's fine to regress #50571, since it's an issue that only has to do with edition 2015 and is a rare enough.
I'd still like to see a better recovery that actually ends up returning Ok(TyKind::Array(...)).
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
4c2fd87 to
edd7377
Compare
| help: you might have meant to use `;` as the separator | ||
| | | ||
| LL | type v = [isize ;* 3]; | ||
| | + |
There was a problem hiding this comment.
This regression is somewhat werid, because parse_expr_anon_const take it as a deref of 3. That maybe reasonable for
const L = &3;
type V = [isize * L];
After applying the suggestion, it is correct.
type V = [isize ;* L];
But IMO, it does not matter in this * case, because after applying the suggestion, compiler will report something like you can not deref a integer, which is reasonable.
There was a problem hiding this comment.
We could perhaps special case both , and * as separators here?
| error: expected `;` or `]`, found `5` | ||
| --> $DIR/array-type-no-semi.rs:15:17 | ||
| | | ||
| LL | let e: [i32 5]; | ||
| | ^ expected `;` or `]` | ||
| | | ||
| = note: you might have meant to write a slice or array type | ||
| help: you might have meant to use `;` as the separator | ||
| | | ||
| LL | let e: [i32 ;5]; | ||
| | + |
There was a problem hiding this comment.
Here is the new case like [i32 5].
This comment has been minimized.
This comment has been minimized.
|
There are changes to the cc @jieyouxu |
; to construct array type when other token exists; to construct array type
| help: you might have meant to use `;` as the separator | ||
| | | ||
| LL | type v = [isize ;* 3]; | ||
| | + |
There was a problem hiding this comment.
We could perhaps special case both , and * as separators here?
| let length = match self.parse_expr_anon_const() { | ||
| Ok(length) => length, | ||
| Err(e) => { | ||
| e.cancel(); | ||
| self.bump(); | ||
| match self.parse_expr_anon_const() { |
There was a problem hiding this comment.
Instead of parsing once then parsing again, could you do:
let suggestion_span = if self.eat(comma) || self.eat(asterisk) {
// Consume common erroneous separators.
self.prev_token.span
} else {
self.token.span.shrink_to_lo()
};
/// then parse the length.
There was a problem hiding this comment.
Should other separators be considered, such as :?
There was a problem hiding this comment.
I think , and * are fine for now
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
|
Yeah, I have instead specially judge |
|
@bors r+ rollup |
Rollup of 13 pull requests Successful merges: - #142301 (tests: Fix duplicated-path-in-error fail with musl) - #143630 (Drop `./x suggest`) - #143736 (Give all bytes of TypeId provenance) - #143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler) - #143837 (Adjust `run_make_support::symbols` helpers) - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - #143905 (Recover and suggest to use `;` to construct array type) - #143907 (core: make `str::split_at_unchecked()` inline) - #143910 (Add experimental `backtrace-trace-only` std feature) - #143927 (Preserve constness in trait objects up to hir ty lowering) - #143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself) - #143938 (Update books) - #143941 (update `cfg_select!` documentation) Failed merges: - #143926 (Remove deprecated fields in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 13 pull requests Successful merges: - rust-lang/rust#142301 (tests: Fix duplicated-path-in-error fail with musl) - rust-lang/rust#143630 (Drop `./x suggest`) - rust-lang/rust#143736 (Give all bytes of TypeId provenance) - rust-lang/rust#143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler) - rust-lang/rust#143837 (Adjust `run_make_support::symbols` helpers) - rust-lang/rust#143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - rust-lang/rust#143905 (Recover and suggest to use `;` to construct array type) - rust-lang/rust#143907 (core: make `str::split_at_unchecked()` inline) - rust-lang/rust#143910 (Add experimental `backtrace-trace-only` std feature) - rust-lang/rust#143927 (Preserve constness in trait objects up to hir ty lowering) - rust-lang/rust#143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself) - rust-lang/rust#143938 (Update books) - rust-lang/rust#143941 (update `cfg_select!` documentation) Failed merges: - rust-lang/rust#143926 (Remove deprecated fields in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
Recover and suggest to use `;` to construct array type Fixes rust-lang#143828 r? compiler
…eltardieu Rollup of 13 pull requests Successful merges: - rust-lang#142301 (tests: Fix duplicated-path-in-error fail with musl) - rust-lang#143630 (Drop `./x suggest`) - rust-lang#143736 (Give all bytes of TypeId provenance) - rust-lang#143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler) - rust-lang#143837 (Adjust `run_make_support::symbols` helpers) - rust-lang#143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - rust-lang#143905 (Recover and suggest to use `;` to construct array type) - rust-lang#143907 (core: make `str::split_at_unchecked()` inline) - rust-lang#143910 (Add experimental `backtrace-trace-only` std feature) - rust-lang#143927 (Preserve constness in trait objects up to hir ty lowering) - rust-lang#143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself) - rust-lang#143938 (Update books) - rust-lang#143941 (update `cfg_select!` documentation) Failed merges: - rust-lang#143926 (Remove deprecated fields in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
Recover `[T: N]` as `[T; N]` `;` is similar and (keyboard-wise) next to `:`, so a verbose suggestion may help to see the difference. Parent PR: rust-lang#143905 --- `@rustbot` label +A-parser +A-array +A-diagnostics +A-suggestion-diagnostics +D-papercut
Rollup merge of #148680 - ShE3py:array-colon, r=JonathanBrouwer Recover `[T: N]` as `[T; N]` `;` is similar and (keyboard-wise) next to `:`, so a verbose suggestion may help to see the difference. Parent PR: #143905 --- `@rustbot` label +A-parser +A-array +A-diagnostics +A-suggestion-diagnostics +D-papercut
Recover `[T: N]` as `[T; N]` `;` is similar and (keyboard-wise) next to `:`, so a verbose suggestion may help to see the difference. Parent PR: rust-lang/rust#143905 --- `@rustbot` label +A-parser +A-array +A-diagnostics +A-suggestion-diagnostics +D-papercut
Recover `[T: N]` as `[T; N]` `;` is similar and (keyboard-wise) next to `:`, so a verbose suggestion may help to see the difference. Parent PR: rust-lang/rust#143905 --- `@rustbot` label +A-parser +A-array +A-diagnostics +A-suggestion-diagnostics +D-papercut
Recover `[T: N]` as `[T; N]` `;` is similar and (keyboard-wise) next to `:`, so a verbose suggestion may help to see the difference. Parent PR: rust-lang#143905 --- `@rustbot` label +A-parser +A-array +A-diagnostics +A-suggestion-diagnostics +D-papercut
Recover `[T: N]` as `[T; N]` `;` is similar and (keyboard-wise) next to `:`, so a verbose suggestion may help to see the difference. Parent PR: rust-lang/rust#143905 --- `@rustbot` label +A-parser +A-array +A-diagnostics +A-suggestion-diagnostics +D-papercut
Recover `[T: N]` as `[T; N]` `;` is similar and (keyboard-wise) next to `:`, so a verbose suggestion may help to see the difference. Parent PR: rust-lang/rust#143905 --- `@rustbot` label +A-parser +A-array +A-diagnostics +A-suggestion-diagnostics +D-papercut
Fixes #143828
r? compiler