Skip to content

needless_borrow suggestion doesn't go far enough #8389

New issue

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

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

Already on GitHub? Sign in to your account

Open
ijackson opened this issue Feb 2, 2022 · 1 comment
Open

needless_borrow suggestion doesn't go far enough #8389

ijackson opened this issue Feb 2, 2022 · 1 comment

Comments

@ijackson
Copy link

ijackson commented Feb 2, 2022

Description

In this code:

fn main() {
    let mut w = [42];
    (&mut w[..]).copy_from_slice(&[43]);
    println!("{:?}", &w);
}

clippy suggests as follows:

4 |     (&mut w[..]).copy_from_slice(&[43]);
  |     ^^^^^^^^^^^^ help: change this to: `w[..]`

This is correct as far as it goes. But a better suggestion would be just w, implying

    w.copy_from_slice(&[43]);

which also DTRT.

FTR, stable doesn't issue this lint in this situation at all. #8367 and #8355 may be relevant.

Version

rustcargo@zealot:/home/ian/Rustup/Arti/experiments$ rustc -Vv
rustc 1.60.0-nightly (a00e130da 2022-01-29)
binary: rustc
commit-hash: a00e130dae74a213338e2b095ec855156d8f3d8a
commit-date: 2022-01-29
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0
rustcargo@zealot:/home/ian/Rustup/Arti/experiments$

Additional Labels

No response

Mohsen7s pushed a commit to Mohsen7s/arti that referenced this issue Feb 7, 2022
Found via clippy::needless_borrow.  In some cases I removed needless
`[..]` too.  See also:
  needless_borrow suggestion doesn't go far enough
  rust-lang/rust-clippy#8389
@matthiaskrgr
Copy link
Member

Hmm, looks like false negative in https://rust-lang.github.io/rust-clippy/master/index.html#redundant_slicing then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants