Skip to content

useless_vec does not consider mutability #7035

Closed
@horacimacias

Description

@horacimacias

I tried this code:

fn on_mut_slice(_: &mut [u8]) {}
fn main() { 
    on_mut_slice(&mut vec![]);
}

I expected to see this happen:
clippy to suggest I could use a mutable reference to a slice.
e.g:

help: you can use a slice directly: `&mut []`

Instead, this happened:
clippy suggested I could use a slice, not mutable, so applying the suggestion results in code not compiling.
suggestion

help: you can use a slice directly: `&[]`

compiler error:

   |     on_mut_slice(&[]);
   |                  ^^^ types differ in mutability

Meta

  • cargo clippy -V: clippy 0.1.51 (2fd73fab 2021-03-23)
  • rustc -Vv:
    rustc 1.51.0 (2fd73fabe 2021-03-23)
    

binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-apple-darwin
release: 1.51.0
LLVM version: 11.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions