-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Recover and suggest to use ;
to construct array type
#143905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
help: use `=` if you meant to assign | ||
| | ||
LL - let b: [i32, 5]; | ||
LL + let b = [i32, 5]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
4c2fd87
to
edd7377
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rustbot ready
help: you might have meant to use `;` as the separator | ||
| | ||
LL | type v = [isize ;* 3]; | ||
| + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should other separators be considered, such as :
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think , and * are fine for now
Signed-off-by: xizheyin <[email protected]>
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
Fixes #143828
r? compiler