-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix match_single_binding
suggestion for assign expressions
#8726
Conversation
r? @xFrednet (rust-highfive has picked a reviewer for you, use r? to override) |
r? @dswij |
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.
LGTM, thanks for the changes!
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.
The refactoring already looks good to me. However, I believe the suggestion should be changed a bit, to keep the same semantics 🙃
LL ~ let (pre, suf) = val.split_at(idx); | ||
LL + val = { | ||
LL + println!("{}", pre); | ||
LL + suf | ||
LL ~ }; |
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.
Shouldn't this suggest the following instead:
val = {
let (pre, suf) = val.split_at(idx);
println!("{}", pre);
suf
};
Having the let <pattern>
before the linted assignment can potentially shadow values. It also extends the lifetime of the pattern values. Now we can access pre
and suf
after the assignment. Which we couldn't previously.
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 it? I know that's what the suggestion was in the issue, but that's how it behaved before I started this.
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.
Yeah, I was under the impression that that's how the suggestion behaved before. But the suggestion will introduce a change in behavior, and that's certainly not what we want.
I think @xFrednet's suggestion makes sense
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.
Okay, then we should change the suggestion. @Serial-ATA Could you make this change? It should be fairly simple, from what I'm guessing. If not, we can also create a new issue and merge this as it is. Your changes are already a solid improvement 🙃
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.
Alright, I'll try it out 🙂
☔ The latest upstream changes (presumably #8797) made this pull request unmergeable. Please resolve the merge conflicts. |
Hey @Serial-ATA, what's the status on this PR? The last unresolved comment was an optional improvement. Do we want to get this merged and created an issue for this possible enhancement? If so, you would just need to rebase, as all changes looked good to us 🙃 @rustbot author |
Completely forgot about this 😄. I tried for some time to make the change, but I couldn't get it to work reliably, unless I'm missing something obvious. I'll make an issue and come back to it soon enough if no one claims it. |
79db0f7
to
df82b55
Compare
@rustbot ready |
📌 Commit 554dc41 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
changelog: Fix suggestion for assign expressions in [
match_single_binding
]closes: #8723