Closed
Description
Lint name: redundant_slicing
While updating rust to 1.51, we hit a false positive on one of the new lints. Here's a minimal reproducer:
use bytes::*; // 1.0.1
fn main() {
let mut storage = &mut [0u8; 512][..];
let bytes = storage.chunk_mut();
{
let mut _bytes_msg = &mut bytes[..];
}
println!("{:?}", bytes);
}
I expected to see this happen: No lint on the slicing at &mut bytes[..]
, as it is required: instead of moving the bytes
variable to _bytes_msg
, thus shortening its lifetime, it will instead create a new borrow with its own lifetime inside of _bytes_msg
.
Instead, this happened: Clippy complained about redundant slicing:
warning: redundant slicing of the whole range
--> src/main.rs:8:30
|
8 | let mut _bytes_msg = &mut bytes[..];
| ^^^^^^^^^^^^^^ help: use the original slice instead: `bytes`
|
= note: `#[warn(clippy::redundant_slicing)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_slicing
warning: 1 warning emitted
Note that this does not reproduce when using a normal &mut [u8]
slice. But bytes.chunk_mut()
returns its own slice-like object UninitSlice
, on which this rule triggers.
Meta
cargo clippy -V
: 0.1.52 (2021-03-24 07e0e2e)rustc -Vv
:rustc 1.51.0 (2fd73fabe 2021-03-23) binary: rustc commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0 commit-date: 2021-03-23 host: x86_64-unknown-linux-gnu release: 1.51.0 LLVM version: 11.0.1