Skip to content

Add a lint to warn about un-necessary .into_iter() #1250

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
merged 3 commits into from
Oct 1, 2016
Merged

Add a lint to warn about un-necessary .into_iter() #1250

merged 3 commits into from
Oct 1, 2016

Conversation

elliottneilclark
Copy link
Contributor

This should close #1094.

@@ -577,6 +596,16 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
object,
method_name));
}
} else if method_name.as_str() == "into_iter" && match_trait_method(cx, arg, &paths::I) {
Copy link
Member

Choose a reason for hiding this comment

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

This should be INTO_ITERATOR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah miss commit.

@@ -87,7 +87,7 @@ impl Unrelated {
}
}

#[deny(needless_range_loop, explicit_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop)]
#[deny(needless_range_loop, explicit_iter_loop, explicit_into_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop)]
Copy link
Member

Choose a reason for hiding this comment

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

We usually just do #[deny(clippy)]. I wonder why this file does not use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't know for sure. Let me clean that up in a separate pr.

@@ -294,6 +294,10 @@ fn main() {
for _v in vec.iter() { } //~ERROR it is more idiomatic to loop over `&vec`
for _v in vec.iter_mut() { } //~ERROR it is more idiomatic to loop over `&mut vec`


let mut _out_vec = vec![1,2,3];
Copy link
Member

@mcarton mcarton Oct 1, 2016

Choose a reason for hiding this comment

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

Why a leading _ here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed. Let me remove it.

@mcarton mcarton merged commit 8babb2d into rust-lang:master Oct 1, 2016
@mcarton
Copy link
Member

mcarton commented Oct 1, 2016

Thanks!

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.

lint unnecessary .into_iter()
2 participants