-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Improve handling of expr->field errors #124200
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
// We make sure the `expr` and `->` are adjacent because we don't want to trigger the | ||
// recovery for function signature. |
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.
Why would this happen?
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.
Removing this makes issue-118530-ice.rs fail. I tried hard to understand this test. My understanding is that line 5 is a function signature, but I'd love to be corrected.
While avoiding this failure by checking the spans is not ideal, this indeed works and is consistent with how people space their ->
in function prototypes and don't space their ->
when accessing fields.
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 feel pretty strongly that we shouldn't be using token connectedness to do this recovery -- if that test ICEs, it would be useful to understand why that happens and fix the recovery rather than just paper it over.
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.
Also, i feel like removing the spaces around the -> in that test example should cause it to still ICE?
if so, this PR still introduces new bugs, and those should be fixed.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
also pls squash this into one commit |
This comment was marked as resolved.
This comment was marked as resolved.
@compiler-errors ah, sorry. I thought making multiple was helpful for the review. This won't happen again. |
It's literally nbd! |
Wait, no it shouldn't 🤦 |
The current message for "`->` used for field access" is the following: ```rust error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->` --> src/main.rs:2:6 | 2 | a->b; | ^^ expected one of 8 possible tokens ``` (playground link[1]) This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is: ``` error: `->` used for field access or method call --> ./tiny_test.rs:2:6 | 2 | a->b; | ^^ help: try using `.` instead | = help: the `.` operator will dereference the value if needed ``` (feel free to bikeshed it as much as necessary) [1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
@rustbot label -S-waiting-on-author +S-waiting-on-review |
👍 thanks for dealing w/ the back and forth @bors r=compiler-errors,fmease |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#123680 (Deny gen keyword in `edition_2024_compat` lints) - rust-lang#124057 (Fix ICE when ADT tail has type error) - rust-lang#124168 (Use `DefiningOpaqueTypes::Yes` in rustdoc, where the `InferCtxt` is guaranteed to have no opaque types it can define) - rust-lang#124197 (Move duplicated code in functions in `tests/rustdoc-gui/notable-trait.goml`) - rust-lang#124200 (Improve handling of expr->field errors) - rust-lang#124220 (Miri: detect wrong vtables in wide pointers) - rust-lang#124266 (remove an unused type from the reentrant lock tests) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124200 - scrabsha:sasha/->, r=compiler-errors,fmease Improve handling of expr->field errors The current message for "`->` used for field access" is the following: ```rust error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->` --> src/main.rs:2:6 | 2 | a->b; | ^^ expected one of 8 possible tokens ``` ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e)) This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is: ``` error: `->` used for field access or method call --> ./tiny_test.rs:2:6 | 2 | a->b; | ^^ help: try using `.` instead | = help: the `.` operator will dereference the value if needed ``` (feel free to bikeshed it as much as necessary)
The current message for "
->
used for field access" is the following:(playground link)
This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is:
(feel free to bikeshed it as much as necessary)