Thanks to visit codestin.com
Credit goes to github.com

Skip to content

iter_not_returning_iterator falsely positiving on every method named iter #8285

@dtolnay

Description

@dtolnay

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions