Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

jfirebaugh
Copy link

@jfirebaugh jfirebaugh commented Feb 18, 2019

Slice patterns without .. are refutable. (Well, except if the match source is an array type -- does is_refutable have enough information to check this though?)

Fixes #3780.

Slice patterns without .. are refutable.
@@ -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
Copy link
Contributor

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

Copy link
Author

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 [..].

@oli-obk
Copy link
Contributor

oli-obk commented Feb 19, 2019

does is_refutable have enough information to check this though?)

Not sure, but we can probably pass in the relevant information

@ghost
Copy link

ghost commented Feb 20, 2019

The patterns [a,..] and [..,b] require at least 1 element so they won't match []. This makes me think that the only irrefutable slice pattern is [..] so maybe just check for that.

@phansch phansch added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 24, 2019
@jfirebaugh
Copy link
Author

does is_refutable have enough information to check this though?

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 ty::Ref, as well as ty::Error. Does anyone know in what situations these arise?

As an aside, it would be nice to lean on the compiler for something like is_refutable. What is the stance toward making items public in, say, rustc_mir solely for the benefit of external tooling like clippy? For example, something like this would presumably be more robust than clippy's current implementation.

@bors
Copy link
Collaborator

bors commented Mar 6, 2019

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

@flip1995
Copy link
Member

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?

@flip1995
Copy link
Member

flip1995 commented Jul 3, 2019

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.

@flip1995 flip1995 closed this Jul 3, 2019
@flip1995 flip1995 added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 3, 2019
@HKalbasi
Copy link
Member

finished in #5559
@rustbot label -S-inactive-closed

@rustbot rustbot removed the S-inactive-closed Status: Closed due to inactivity label Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad while_let_on_iterator suggestion when pattern is refutable
7 participants