-
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 invalid while_let_on_iterator suggestion #3784
Conversation
Slice patterns without .. are refutable.
clippy_lints/src/utils/mod.rs
Outdated
@@ -958,7 +958,11 @@ pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat) -> bool { | |||
} | |||
}, | |||
PatKind::Slice(ref head, ref middle, ref tail) => { | |||
are_refutable(cx, head.iter().chain(middle).chain(tail.iter()).map(|pat| &**pat)) | |||
if middle.is_none() { | |||
true |
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.
It might still be irrefutable if head
or tail
are irrefutable
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.
Are you referring to matches on array types? As @mikerite points out, the only irrefutable slice pattern on slices is [..]
.
Not sure, but we can probably pass in the relevant information |
The patterns |
It appears so; I've added type-checking in the latest commit, though I am not too sure of its correctness. I see that MIR handles the case where the pattern is As an aside, it would be nice to lean on the compiler for something like |
☔ The latest upstream changes (presumably #3803) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping @jfirebaugh. I'm going over old PRs, that were abandoned by us reviewers (sorry for that!) or by the authors. Are you still interested in completing this? |
Ping from triage @jfirebaugh. Sorry for neglecting this PR and thanks for your contribution. If you want to continue working on this, feel free to reopen and ping me. I'll be happy to help you wrapping this up. |
Slice patterns without
..
are refutable. (Well, except if the match source is an array type -- doesis_refutable
have enough information to check this though?)Fixes #3780.