Skip to content

significant-drop-in-scrutinee when false positive #8963

Closed
@aviramha

Description

@aviramha

Summary

Last version of clippy seems to have false positive on the lint
happens in our CI
https://github.com/metalbear-co/mirrord/runs/6770432194?check_suite_focus=true

Lint Name

significant-drop-in-scrutinee

Reproducer

I tried this code:

pub(crate) static SOCKETS: SyncLazy<Mutex<HashSet<Socket>>> =
    SyncLazy::new(|| Mutex::new(HashSet::new()));

fn bind(sockfd: c_int, addr: *const sockaddr, addrlen: socklen_t) -> c_int {
    debug!("bind called sockfd: {:?}", sockfd);
    let mut socket = {
        let mut sockets = SOCKETS.lock().unwrap();
        match sockets.take(&sockfd) {
            Some(socket) if !matches!(socket.state, SocketState::Initialized) => {
                error!("socket is in invalid state for bind {:?}", socket.state);
                return libc::EINVAL;
            }
            Some(socket) => socket,
            None => {
                debug!("bind: no socket found for fd: {}", &sockfd);
                return unsafe { libc::bind(sockfd, addr, addrlen) };
            }
        }
    };
....

I saw this happen:

   --> mirrord-layer/src/sockets.rs:168:15
    |
168 |         match sockets.take(&sockfd) {
    |               ^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D clippy::significant-drop-in-scrutinee` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee

Version

rustc 1.63.0-nightly (50b00252a 2022-06-06) (from rustc 1.63.0-nightly (50b00252a 2022-06-06))

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