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

iter_not_returning_iterator falsely positiving on every method named iter #8285

Closed
dtolnay opened this issue Jan 15, 2022 · 1 comment · Fixed by #8287
Closed

iter_not_returning_iterator falsely positiving on every method named iter #8285

dtolnay opened this issue Jan 15, 2022 · 1 comment · Fixed by #8287
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
Copy link
Member

dtolnay commented Jan 15, 2022

Summary

As of most recent nightly, and as of current master of clippy (7a4acf9), I haven't found a function named iter or iter_mut which does not trigger this lint. Even if the function returns an implementation of Iterator the lint triggers.

Lint Name

iter_not_returning_iterator

Reproducer

#![deny(clippy::iter_not_returning_iterator)]

pub struct Matrix;
pub struct Element;

impl Matrix {
    pub fn iter(&self) -> Iter {
        Iter([].iter())
    }
}

pub struct Iter<'a>(std::slice::Iter<'a, Element>);

impl<'a> Iterator for Iter<'a> {
    type Item = &'a Element;

    fn next(&mut self) -> Option<Self::Item> {
        self.0.next()
    }
}
error: this method is named `iter` but its return type does not implement `Iterator`
 --> src/main.rs:7:5
  |
7 |     pub fn iter(&self) -> Iter {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(clippy::iter_not_returning_iterator)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator

Version

rustc 1.60.0-nightly (ad46af247 2022-01-14)
binary: rustc
commit-hash: ad46af24713115e7b9b258346e66b9b2d14eacfc
commit-date: 2022-01-14
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0

Additional Labels

No response

@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 15, 2022
@dtolnay
Copy link
Member Author

dtolnay commented Jan 15, 2022

Mentioning @Jarcho @giraffate who touched this lint recently.

dtolnay added a commit to dtolnay/syn that referenced this issue Jan 15, 2022
rust-lang/rust-clippy#8285

    error: this method is named `iter` but its return type does not implement `Iterator`
      --> src/data.rs:79:5
       |
    79 |     pub fn iter(&self) -> punctuated::Iter<Field> {
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `-D clippy::iter-not-returning-iterator` implied by `-D clippy::pedantic`
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator

    error: this method is named `iter_mut` but its return type does not implement `Iterator`
      --> src/data.rs:90:5
       |
    90 |     pub fn iter_mut(&mut self) -> punctuated::IterMut<Field> {
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator

    error: this method is named `iter` but its return type does not implement `Iterator`
       --> src/punctuated.rs:105:5
        |
    105 |     pub fn iter(&self) -> Iter<T> {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator

    error: this method is named `iter_mut` but its return type does not implement `Iterator`
       --> src/punctuated.rs:116:5
        |
    116 |     pub fn iter_mut(&mut self) -> IterMut<T> {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
dtolnay added a commit to dtolnay/serde-yaml that referenced this issue Jan 15, 2022
rust-lang/rust-clippy#8285

    error: this method is named `iter` but its return type does not implement `Iterator`
       --> src/mapping.rs:123:5
        |
    123 |     pub fn iter(&self) -> Iter {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `-D clippy::iter-not-returning-iterator` implied by `-D clippy::pedantic`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator

    error: this method is named `iter_mut` but its return type does not implement `Iterator`
       --> src/mapping.rs:132:5
        |
    132 |     pub fn iter_mut(&mut self) -> IterMut {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
dtolnay added a commit to dtolnay/path-to-error that referenced this issue Jan 15, 2022
rust-lang/rust-clippy#8285

    error: this method is named `iter` but its return type does not implement `Iterator`
      --> src/path.rs:27:5
       |
    27 |     pub fn iter(&self) -> Segments {
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `-D clippy::iter-not-returning-iterator` implied by `-D clippy::pedantic`
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
dtolnay added a commit to dtolnay/trybuild that referenced this issue Jan 15, 2022
rust-lang/rust-clippy#8285

    error: this method is named `iter` but its return type does not implement `Iterator`
      --> src/diff.rs:76:9
       |
    76 |         pub fn iter(&self, _input: &str) -> Box<dyn Iterator<Item = Render>> {
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `-D clippy::iter-not-returning-iterator` implied by `-D clippy::pedantic`
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
dtolnay added a commit to serde-rs/json that referenced this issue Jan 15, 2022
rust-lang/rust-clippy#8285

    error: this method is named `iter` but its return type does not implement `Iterator`
       --> src/map.rs:238:5
        |
    238 |     pub fn iter(&self) -> Iter {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `-D clippy::iter-not-returning-iterator` implied by `-D clippy::pedantic`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator

    error: this method is named `iter_mut` but its return type does not implement `Iterator`
       --> src/map.rs:246:5
        |
    246 |     pub fn iter_mut(&mut self) -> IterMut {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
dtolnay added a commit to dtolnay/cargo-tally that referenced this issue Jan 15, 2022
rust-lang/rust-clippy#8285

    error: this method is named `iter` but its return type does not implement `Iterator`
      --> src/matrix.rs:37:5
       |
    37 |     pub fn iter(&self) -> Iter {
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `-D clippy::iter-not-returning-iterator` implied by `-D clippy::pedantic`
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
@bors bors closed this as completed in 496f26c Jan 15, 2022
ronaldslc pushed a commit to ronaldslc/serde-json that referenced this issue Dec 3, 2022
rust-lang/rust-clippy#8285

    error: this method is named `iter` but its return type does not implement `Iterator`
       --> src/map.rs:238:5
        |
    238 |     pub fn iter(&self) -> Iter {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `-D clippy::iter-not-returning-iterator` implied by `-D clippy::pedantic`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator

    error: this method is named `iter_mut` but its return type does not implement `Iterator`
       --> src/map.rs:246:5
        |
    246 |     pub fn iter_mut(&mut self) -> IterMut {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant