Skip to content

Fix invalid while_let_on_iterator suggestion#3784

Closed
jfirebaugh wants to merge 3 commits into
rust-lang:masterfrom
jfirebaugh:fix-3780
Closed

Fix invalid while_let_on_iterator suggestion#3784
jfirebaugh wants to merge 3 commits into
rust-lang:masterfrom
jfirebaugh:fix-3780

Conversation

@jfirebaugh

@jfirebaugh jfirebaugh commented Feb 18, 2019

Copy link
Copy Markdown

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.
Comment thread clippy_lints/src/utils/mod.rs Outdated
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
Copy Markdown
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
Copy Markdown
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

oli-obk commented Feb 19, 2019

Copy link
Copy Markdown
Contributor

does is_refutable have enough information to check this though?)

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

@ghost

ghost commented Feb 20, 2019

Copy link
Copy Markdown

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
Copy Markdown
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

bors commented Mar 6, 2019

Copy link
Copy Markdown
Contributor

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

@flip1995

Copy link
Copy Markdown
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

flip1995 commented Jul 3, 2019

Copy link
Copy Markdown
Member

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
Copy Markdown
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