Recover and suggest to use ; to construct array type by xizheyin · Pull Request #143905 · rust-lang/rust (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation27 Commits2 Checks11 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Comment on lines 15 to 18
| help: use `=` if you meant to assign |
|---|
| | |
| LL - let b: [i32, 5]; |
| LL + let b = [i32, 5]; |
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
rustbot added S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Reminder, once the PR becomes ready for a review, use @rustbot ready.
Also, why can't we emit the error and then return TyKind::Array, so we can recover successfully rather than propagating an error?
Yeah, I have tried to recover it to TyKind::Array, but It emit a regression. In this test, it will emit error: expected ; or ], found , immidiately, which is wrong. It just want call parse_ty_common for Some(x), while in this case, it parse it into Array and give a wrong suggestion.
https://github.com/rust-lang/rust/blob/master/tests/ui/issues/issue-50571.rs
https://github.com/rust-lang/rust/blob/master/tests/ui/issues/issue-50571.stderr
@rustbot ready
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
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(...)).
rustbot added S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Signed-off-by: xizheyin xizheyin@smail.nju.edu.cn
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| help: you might have meant to use `;` as the separator |
|---|
| | |
| LL | type v = [isize ;* 3]; |
| | + |
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.
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.
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?
Comment on lines +38 to +48
| 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]; |
| | + |
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].
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
This comment has been minimized.
Area: The tidy tool
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
labels
There are changes to the tidy tool.
cc @jieyouxu
xizheyin changed the title
Suggest use Recover and suggest to use ; 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]; |
| | + |
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?
Comment on lines 609 to 614
| let length = match self.parse_expr_anon_const() { |
|---|
| Ok(length) => length, |
| Err(e) => { |
| e.cancel(); |
| self.bump(); |
| match self.parse_expr_anon_const() { |
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.
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 :?
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 xizheyin@smail.nju.edu.cn
Yeah, I have instead specially judge , and *.
📌 Commit ed88af2 has been approved by compiler-errors
It is now in the queue for this repository.
bors added S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
bors added a commit that referenced this pull request
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::symbolshelpers) - #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-onlystd feature) - #143927 (Preserve constness in trait objects up to hir ty lowering)
- #143935 (rustc_type_ir/walk: move docstring to
TypeWalkeritself) - #143938 (Update books)
- #143941 (update
cfg_select!documentation)
Failed merges:
- #143926 (Remove deprecated fields in bootstrap)
r? @ghost
@rustbot modify labels: rollup
rust-timer added a commit that referenced this pull request
Rollup merge of #143905 - xizheyin:143828, r=compiler-errors
Recover and suggest to use ; to construct array type
Fixes #143828
r? compiler
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request
Muscraft pushed a commit to Muscraft/rust that referenced this pull request
Recover and suggest to use ; to construct array type
Fixes rust-lang#143828
r? compiler
Muscraft pushed a commit to Muscraft/rust that referenced this pull request
Zalathar added a commit to Zalathar/rust that referenced this pull request
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
rust-timer added a commit that referenced this pull request
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
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request
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
makai410 pushed a commit to makai410/rustc_public that referenced this pull request
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
makai410 pushed a commit to makai410/rust that referenced this pull request
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
makai410 pushed a commit to makai410/rustc_public that referenced this pull request
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
Labels
Area: The tidy tool
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Relevant to the compiler team, which will review and decide on the PR/issue.