-
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 have
Description
Summary
Upgrading to Rust 1.80.0 has clippy making suggestions that break compilation of the code once applied.
Lint Name
needless_borrows_for_generic_args
Reproducer
I tried this code:
// uses md-5 = "0.10.6"
#![warn(clippy::needless_borrows_for_generic_args)]
use md5::{Digest, Md5};
pub fn problem(data: &mut Vec<u8>) {
let mut hasher = Md5::new();
hasher.update(&data);
data.push(0);
}
I saw this happen:
warning: the borrowed expression implements the required traits
--> src/lib.rs:6:19
|
6 | hasher.update(&data);
| ^^^^^ help: change this to: `data`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
And once applied:
error[E0382]: borrow of moved value: `data`
--> src/lib.rs:7:5
|
4 | pub fn problem(data: &mut Vec<u8>) {
| ---- move occurs because `data` has type `&mut std::vec::Vec<u8>`, which does not implement the `Copy` trait
5 | let mut hasher = Md5::new();
6 | hasher.update(data);
| ---- value moved here
7 | data.push(0);
| ^^^^ value borrowed here after move
|
help: consider cloning the value if the performance cost is acceptable
|
6 | hasher.update(data).clone();
| ++++++++
This is likely related to #13162 and #13170 but adding it for what could be a simpler example in case it helps.
Version
rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: x86_64-unknown-linux-gnu
release: 1.80.0
LLVM version: 18.1.7
Additional Labels
No response
RisaI
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 have