Skip to content

lines_filter_map_ok should also warn for flatten #11686

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

Closed
georgmu opened this issue Oct 19, 2023 · 1 comment · Fixed by #11691
Closed

lines_filter_map_ok should also warn for flatten #11686

georgmu opened this issue Oct 19, 2023 · 1 comment · Fixed by #11691
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@georgmu
Copy link

georgmu commented Oct 19, 2023

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
@georgmu georgmu added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Oct 19, 2023
@sjwang05
Copy link
Contributor

@rustbot claim

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-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants