Skip to content

Fix invalid suggestions on unit range bindings #97505

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

Closed

Conversation

JohnTitor
Copy link
Member

Fixes #93122

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 29, 2022
@rust-highfive
Copy link
Contributor

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 29, 2022
Comment on lines +2013 to +2019
let suggestion = if exp_found.found.is_unit() {
let exp_str = format!("{:?}", expected_def);

// `RangeInclusive`'s fields are private, we have to call methods instead.
if exp_str.contains("core::ops::RangeInclusive")
|| exp_str.contains("std::ops::RangeInclusive")
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right approach. I would instead add a &hir::Expr (or a HirId to get the expression back) to Pattern so that we can then call .precedence() and compare it to ExprPrecedence::Field. This will work regardless of the types. Also, with access to the expression itself, it'd be nice to see if notice these kind of range literals to suggest changing the range to the start or end, instead of constructing the range and then field accessing one of those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've tried to implement your suggestion but it would be a bigger change than I thought. I'm going to ask some questions on Zulip once I get some time to summarize them!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to waiting on author then :) Feel free to request a review when ready, thanks!

@rustbot author

@rustbot 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 Jun 30, 2022
@bors
Copy link
Collaborator

bors commented Dec 9, 2022

☔ The latest upstream changes (presumably #105486) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@JohnTitor any updates on this pr?

@JohnTitor
Copy link
Member Author

JohnTitor commented Dec 11, 2022

Totally forgot about this PR, sorry! Since the branch is quite old and I'm not sure when I have time to work on this, I'm going to close for now.

@JohnTitor JohnTitor closed this Dec 11, 2022
@JohnTitor JohnTitor deleted the unit-range-invalid-sugg branch December 11, 2022 13:17
@Dylan-DPC
Copy link
Member

No worries. Thanks for the update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message for trying to bind range of units to unit suggests invalid code
7 participants