Skip to content

needless_borrows_for_generic_arg seems to have introduced suggestions that break compilation for 1.80.0 #13218

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
MarcoLugo opened this issue Aug 4, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@MarcoLugo
Copy link

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

@MarcoLugo MarcoLugo added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Aug 4, 2024
@Jarcho
Copy link
Contributor

Jarcho commented Aug 7, 2024

Fixed in #12892.

@Jarcho Jarcho closed this as completed Aug 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants