Skip to content

needless_pass_by_ref_mut false positive in nested async #11299

Closed
@hatoo

Description

@hatoo

Summary

needless_pass_by_ref_mut false positive

I think it's another variant of #11179, sorry if this issue is a duplicate.

Lint Name

needless_pass_by_ref_mut

Reproducer

I tried this code:

async fn f(x: &mut i32) {
    async {
        *x += 1;
    }
    .await;
}

I saw this happen:

❯ cargo +nightly clippy 
warning: this argument is a mutable reference, but not used mutably
 --> src/main.rs:8:15
  |
8 | async fn f(x: &mut i32) {
  |               ^^^^^^^^ help: consider changing to: `&i32`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
  = note: `#[warn(clippy::needless_pass_by_ref_mut)]` on by default

I expected to see this happen:

No warning

Version

rustc 1.73.0-nightly (eb088b8b9 2023-08-05)
binary: rustc
commit-hash: eb088b8b9d98f1af1b0e61bbdcd8686e1b0db7b6
commit-date: 2023-08-05
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

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