-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
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
Centri3
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied