Skip to content

needless_borrow suggestion doesn't go far enough #8389

Open

Description

@ijackson

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

Activity

  1. matthiaskrgr commented on Feb 12, 2022

    @matthiaskrgr
    Member
  2. added
    C-bugCategory: Clippy is not doing the correct thing
    I-false-negativeIssue: The lint should have been triggered on code, but wasn't
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions