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

Encountered spurious Does not need to be mutable warning #88125

Closed
sadmac7000 opened this issue Aug 17, 2021 · 1 comment
Closed

Encountered spurious Does not need to be mutable warning #88125

sadmac7000 opened this issue Aug 17, 2021 · 1 comment
Labels
A-async-await Area: Async & Await A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@sadmac7000
Copy link

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.

@jonas-schievink jonas-schievink added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels Aug 17, 2021
@tmandry tmandry added the A-async-await Area: Async & Await label Aug 17, 2021
@sadmac7000
Copy link
Author

This looks to be caused due to some proc macro shenanigans that we're up to in this code base, hence the difficulty reproducing. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants