RS.CLIPPY.NEEDLESS_PASS_BY_REF_MUT

Using a `&mut` argument when it's not mutated

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: needless_pass_by_ref_mut. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Check if a &mut function argument is actually used mutably.

Be careful if the function is publicly reexported as it would break compatibility with users of this function, when the users pass this function as an argument.

Why is this bad?

Less mut means less fights with the borrow checker. It can also lead to more opportunities for parallelization.

Example

fn foo(y: &mut i32) -> i32 {
    12 + *y
}

Use instead:

fn foo(y: &i32) -> i32 {
    12 + *y
}

Configuration

  • avoid-breaking-exported-api: Suppress lints whenever the suggested change would cause breakage for other crates.

    (default: true)