Skip to content

needless_pass_by_ref_mut false positive because of type change #11182

Closed
@smoelius

Description

@smoelius

Summary

A function may require an &mut argument so that it has a particular type.

Lint Name

needless_pass_by_ref_mut

Reproducer

I tried this code (note that foo needs to have the &mut argument to be passed to bar):

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

fn bar(_: impl Fn(&mut i32) -> i32) {}

fn main() {
    bar(foo);
}

I saw this happen:

warning: this argument is a mutable reference, but not used mutably
 --> src/main.rs:1:11
  |
1 | fn foo(y: &mut i32) -> 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 (da6b55cc5 2023-07-17)
binary: rustc
commit-hash: da6b55cc5eaf76ed6acb7dc2f7d611e32af7c9a7
commit-date: 2023-07-17
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 haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions