-
Notifications
You must be signed in to change notification settings - Fork 1.6k
manual_let_else: support struct patterns #10866
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
At the top level, () are required, but on the levels below they are not.
r? @Manishearth (rustbot has picked a reviewer for you, use r? to override) |
@Centri3 this is an interesting PR; would you like to review it as well? No worries if not. (trying to point contributors at interesting PRs to review to get more folks who know how to review things) |
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.
Mostly looks good. I want to have a closer look later, and perhaps wait for @Centri3's review if she is interested.
clippy_lints/src/manual_let_else.rs
Outdated
|
||
// There is some length mismatch, which indicates usage of .. in the patterns above e.g.: | ||
// let (a, ..) = if let [a, b, _c] = ex { (a, b) } else { ... }; | ||
// For now, bail in these cases. |
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.
thought: seems reasonable; i can't think of any big reason to do this beyond WIP code.
pat_bindings.insert(ident); | ||
}); | ||
if pat_bindings.len() < paths.len() { | ||
return false; | ||
// This rebinds some bindings from the outer scope, or it repeats some copy-able bindings multiple | ||
// times. We don't support these cases so we bail here. E.g.: |
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.
thought: probably possible to split into two let
s, probably not worth it.
(Might be interesting to design a different lint that detects when let (a, b) = ...
is splittable)
6211a3a
to
71140d8
Compare
71140d8
to
f538402
Compare
Looks good overall, I have nothing to add past what was commented on already |
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This adds upon the improvements of #10797 and:
()
aroundOr
patterns at the top level (fixing a regression of Improve pattern printing for manual_let_else #10797)let (u, v) = if let (Some(u_i), Ok(v_i)) = ex { (u_i, v_i) } else ...
let v = if let (Some(v), None) = ex { v } else ...
let v = if let S { v, w, } = ex { (v, w) } else ...
fixes #10708
fixes #10424