Skip to content
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

useless_vec does not consider mutability #7035

Closed
horacimacias opened this issue Apr 5, 2021 · 0 comments · Fixed by #7036
Closed

useless_vec does not consider mutability #7035

horacimacias opened this issue Apr 5, 2021 · 0 comments · Fixed by #7036
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@horacimacias
Copy link

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

@horacimacias horacimacias added the C-bug Category: Clippy is not doing the correct thing label Apr 5, 2021
bors added a commit that referenced this issue Apr 6, 2021
consider mutability on useless_vec suggestions

fixes #7035

changelog:
Now the suggested text considers mutability to suggest either `&[]`, as before, or `&mut []` if the used reference is mutable.
@bors bors closed this as completed in d2ba777 Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant