Skip to content
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

manual_flatten suggests code that does not compile #7538

Closed
xobs opened this issue Aug 6, 2021 · 3 comments · Fixed by #7566
Closed

manual_flatten suggests code that does not compile #7538

xobs opened this issue Aug 6, 2021 · 3 comments · Fixed by #7566
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@xobs
Copy link

xobs commented Aug 6, 2021

Lint name:

manual_flatten

I tried this code:

for server in self.servers.iter_mut() {
    if let Some(server_inner) = server {
        if server_inner.pid == target_pid {
            *server = None;
        }
    }
}

I expected to see this happen: The lint should not have been emitted. Alternately, the suggestion should have resulted in code that compiled.

Instead, this happened: The Quick fix resulted in code that did not compile.

Meta

  • cargo clippy -V: clippy 0.1.54 (a178d032 2021-07-26)
  • rustc -Vv:
    rustc 1.54.0 (a178d0322 2021-07-26)
    binary: rustc
    commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
    commit-date: 2021-07-26
    host: x86_64-pc-windows-msvc
    release: 1.54.0
    LLVM version: 12.0.1
    
@xobs xobs added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Aug 6, 2021
@dswij
Copy link
Member

dswij commented Aug 9, 2021

Depending on what servers is, this might be related to #7514.

@xobs can you help clarify what servers is, or better provide a minimal example that we can run/test on?

@xobs
Copy link
Author

xobs commented Aug 9, 2021

Sure, here's a minimal example:

#[derive(Debug)]
struct Server {
    pid: u32,
}

fn main() {
    let target_pid = 1u32;
    let mut servers = [
        None,
        None,
        Some(Server { pid: 0u32 }),
        Some(Server { pid: 1u32 }),
    ];
    for server in servers.iter_mut() {
        if let Some(server_inner) = server {
            if server_inner.pid == target_pid {
                *server = None;
            }
        }
    }
    println!("Servers: {:x?}", servers);
}

Here's a link to the Playground, which also gives this recommendation: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=265c9480c7cbb542e9dd26aca6562c2b

@dswij
Copy link
Member

dswij commented Aug 14, 2021

Thanks for the minimal example!

This seems to be similar to #6784, I think we can close one in favor of the other.

@bors bors closed this as completed in 983e5b8 Aug 16, 2021
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-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants