Skip to content

manual_flatten doesn't follow its suggestion to remove if let statement leading to broken code #14692

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

Open
ulrichstark opened this issue Apr 25, 2025 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@ulrichstark
Copy link

Summary

Clippy lint manual_flatten doesn't follow its own suggestion to remove if let statement leading to broken code.
Similar to #7514, but without references or slices.

Reproducer

I tried this code:

fn main() {
    let results: Vec<Result<String, ()>> = vec![];

    for result in results {
        if let Ok(value) = result {
            println!("{value}");
        }
    }
}

I expected to see this happen:

for result in results.into_iter().flatten() {
    println!("{result}");
}

Instead, this happened:

for result in results.into_iter().flatten() {
    if let Ok(value) = result { // broken because result is now of type String
        println!("{value}");
    }
}

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-pc-windows-msvc
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

@rustbot label +I-suggestion-causes-error

@ulrichstark ulrichstark added the C-bug Category: Clippy is not doing the correct thing label Apr 25, 2025
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Apr 25, 2025
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

2 participants