-
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
into_iter_without_iter false positive when there is a Deref impl #11635
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Comments
dtolnay
added a commit
to dtolnay/miniserde
that referenced
this issue
Oct 7, 2023
rust-lang/rust-clippy#11635 warning: `IntoIterator` implemented for a reference type without an `iter` method --> src/json/array.rs:72:1 | 72 | / impl<'a> IntoIterator for &'a Array { 73 | | type Item = &'a Value; 74 | | type IntoIter = <&'a Vec<Value> as IntoIterator>::IntoIter; 75 | | ... | 78 | | } 79 | | } | |_^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_without_iter = note: `-W clippy::into-iter-without-iter` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::into_iter_without_iter)]` help: consider implementing `iter` | 72 + 73 + impl Array { 74 + fn iter(&self) -> <&'a Vec<Value> as IntoIterator>::IntoIter { 75 + <&Self as IntoIterator>::into_iter(self) 76 + } 77 + } | warning: `IntoIterator` implemented for a reference type without an `iter_mut` method --> src/json/array.rs:81:1 | 81 | / impl<'a> IntoIterator for &'a mut Array { 82 | | type Item = &'a mut Value; 83 | | type IntoIter = <&'a mut Vec<Value> as IntoIterator>::IntoIter; 84 | | ... | 87 | | } 88 | | } | |_^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_without_iter help: consider implementing `iter_mut` | 81 + 82 + impl Array { 83 + fn iter_mut(&mut self) -> <&'a mut Vec<Value> as IntoIterator>::IntoIter { 84 + <&mut Self as IntoIterator>::into_iter(self) 85 + } 86 + } | warning: `IntoIterator` implemented for a reference type without an `iter` method --> src/json/object.rs:66:1 | 66 | / impl<'a> IntoIterator for &'a Object { 67 | | type Item = (&'a String, &'a Value); 68 | | type IntoIter = <&'a BTreeMap<String, Value> as IntoIterator>::IntoIter; 69 | | ... | 72 | | } 73 | | } | |_^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_without_iter help: consider implementing `iter` | 66 + 67 + impl Object { 68 + fn iter(&self) -> <&'a BTreeMap<String, Value> as IntoIterator>::IntoIter { 69 + <&Self as IntoIterator>::into_iter(self) 70 + } 71 + } | warning: `IntoIterator` implemented for a reference type without an `iter_mut` method --> src/json/object.rs:75:1 | 75 | / impl<'a> IntoIterator for &'a mut Object { 76 | | type Item = (&'a String, &'a mut Value); 77 | | type IntoIter = <&'a mut BTreeMap<String, Value> as IntoIterator>::IntoIter; 78 | | ... | 81 | | } 82 | | } | |_^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_without_iter help: consider implementing `iter_mut` | 75 + 76 + impl Object { 77 + fn iter_mut(&mut self) -> <&'a mut BTreeMap<String, Value> as IntoIterator>::IntoIter { 78 + <&mut Self as IntoIterator>::into_iter(self) 79 + } 80 + } |
Yeah, I guess we can walk the deref impl chain and look for |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
In https://rust-lang.github.io/rust-clippy/master/index.html#/into_iter_without_iter,
into_iter_without_iter
is motivated by letting users write the simplerval.iter()
instead of<&Type>::into_iter(val)
or(&val).into_iter()
.However, there are cases where a
fn iter
is not needed in order for.iter()
to be available. Namely for a type with a Deref impl, whereval.deref().iter()
returns the same thing as(&val).into_iter()
, the simpleval.iter()
already works (and will be shown in the documentation by rustdoc). Handwriting afn iter
is needless boilerplate.Lint Name
into_iter_without_iter
Reproducer
In the following code, clippy wants
fn iter
so thatThing(...).iter()
works. ButThing(...).iter()
already works.Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: