Skip to content

False positive with Box<dyn Iterator<>> and iter_not_returning_iterator  #8308

Closed
@HollayHorvath

Description

@HollayHorvath

Summary

Having an function returning a boxed iterator triggers this lint.

Lint Name

iter_not_returning_iterator

Reproducer

I tried this code:

pub trait Foo {
    fn iter(&self) -> Box<dyn Iterator<Item = i32> + '_>;
}

I saw this happen:

warning: this method is named `iter` but its return type does not implement `Iterator`
 --> src/lib.rs:3:5
  |
3 |     fn iter(&self) -> Box<dyn Iterator<Item = i32> + '_>;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::iter_not_returning_iterator)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator

I expected to see this happen:
No warn being triggered

Version

rustc 1.60.0-nightly (bd3cb5256 2022-01-16)
binary: rustc
commit-hash: bd3cb52565faab2755ff1bdb54d88bc91f47b4b9
commit-date: 2022-01-16
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