Skip to content

Encountered spurious Does not need to be mutable warning #88125

@sadmac7000

Description

@sadmac7000

I had the following function in my code:

pub async fn forward_tcp(forward_port: bridge::ForwardPortProxy, cmd: TcpCommand) -> Result<()> {   
    let mut cmd = cmd;                                                                              
    forward_port                                                                                    
        .forward_port(None, &mut cmd.host_address, &mut cmd.target_address)                         
        .await?                                                                                     
        .map_err(|x| anyhow!("Failed to establish port forward: {:?}", x))                          
}

Getting rid of the mut on the second line and making the cmd argument mutable instead resulted in a "Warning: 'cmd' does not need to be mutable" message. Getting rid of the mut entirely caused the program to fail to compile due to the mutable references.

I've not gotten a simpler reproducer to behave this way in isolation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions