Skip to content

lines_filter_map_ok should also warn for flatten #11686

Closed
@georgmu

Description

@georgmu

Summary

When stumbling about the clippy warning lines_filter_map_ok , I tried a different solution by using flatten(). The clippy warning disappears

I tested the code with a directory (as described in the lint) and it still loops forever.

Lint Name

lines_filter_map_ok

Reproducer

I tried this code snippet:

let f = File::open(".")?; // open a directory
let f = BufReader::new(f);

let numbered_lines_iter = f
    .lines()
    .flatten() // <- has same behavior as .flat_map(Result::ok)
    .enumerate();

let first_line = numbered_lines_iter.next(); // this loops forever

I expected to see this happen:
Since flatten() is more or less the same as flat_map, it should warn as well

Instead, this happened:
No warnings

Version

rustc 1.75.0-nightly (0039d739d 2023-10-18)
binary: rustc
commit-hash: 0039d739d40a076334e111488946441378d11cd7
commit-date: 2023-10-18
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions