Skip to content

Note known false positives in unnecessary_fold lint #3303

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

Merged

Conversation

shssoichiro
Copy link
Contributor

@shssoichiro shssoichiro commented Oct 12, 2018

Methods like Iterator::any borrow the iterator mutably,
which is not allowed within a pattern guard and will fail to compile.

See #3069

Methods like `Iterator::any` borrow the iterator mutably,
which is not allowed within a pattern guard and will fail to compile.
This commit prevents clippy from suggesting this type of change.

Closes rust-lang#3069
// `Iterator::any` cannot be used within a pattern guard
// See https://github.com/rust-lang-nursery/rust-clippy/issues/3069
if_chain! {
if let Some(fold_parent) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(expr.id));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably doesn't work if the pattern guard is even a slight variation of the test (so e.g. ((0..3).fold(false, |acc, x| acc || x > 2), 42).0. I don't see a good way to fix this issue. It seems like an unfortunate restriction of the language that will get fixed at some point. I think users should rather disable the lint than us trying to hide the false positive.

It also seems like there's ongoing work in the compiler towards fixing this: https://play.rust-lang.org/?gist=1ec006ebd816427e4acbf21f2156d6e2&version=nightly&mode=debug&edition=2015

We could list this as a known issue in the lint description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see; that is indeed an issue. If there is an upcoming compiler feature to fix this, then I agree, I would rather wait for that, and update the documentation instead.

@shssoichiro shssoichiro changed the title Exclude pattern guards from unnecessary_fold lint Note known false positives in unnecessary_fold lint Oct 16, 2018
@phansch phansch merged commit 8f5a248 into rust-lang:master Oct 18, 2018
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.

3 participants