2022-01-03 20:25:00 +00:00
|
|
|
// run-rustfix
|
|
|
|
|
2020-12-31 16:10:13 +00:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::redundant_slicing)]
|
|
|
|
|
|
|
|
fn main() {
|
2021-03-26 02:30:14 +00:00
|
|
|
let slice: &[u32] = &[0];
|
2022-01-03 20:25:00 +00:00
|
|
|
let _ = &slice[..]; // Redundant slice
|
2020-12-31 16:10:13 +00:00
|
|
|
|
|
|
|
let v = vec![0];
|
2022-01-03 20:25:00 +00:00
|
|
|
let _ = &v[..]; // Deref instead of slice
|
|
|
|
let _ = &(&*v)[..]; // Outer borrow is redundant
|
2021-03-26 02:30:14 +00:00
|
|
|
|
|
|
|
static S: &[u8] = &[0, 1, 2];
|
|
|
|
let err = &mut &S[..]; // Should reborrow instead of slice
|
|
|
|
|
|
|
|
let mut vec = vec![0];
|
2022-01-03 20:25:00 +00:00
|
|
|
let mut_slice = &mut vec[..]; // Deref instead of slice
|
2021-03-26 02:30:14 +00:00
|
|
|
let _ = &mut mut_slice[..]; // Should reborrow instead of slice
|
|
|
|
|
2022-01-03 20:25:00 +00:00
|
|
|
let ref_vec = &vec;
|
|
|
|
let _ = &ref_vec[..]; // Deref instead of slice
|
|
|
|
|
2021-03-26 02:30:14 +00:00
|
|
|
macro_rules! m {
|
|
|
|
($e:expr) => {
|
|
|
|
$e
|
|
|
|
};
|
|
|
|
}
|
|
|
|
let _ = &m!(slice)[..];
|
|
|
|
|
|
|
|
macro_rules! m2 {
|
|
|
|
($e:expr) => {
|
|
|
|
&$e[..]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
let _ = m2!(slice); // Don't lint in a macro
|
2022-01-03 20:25:00 +00:00
|
|
|
|
|
|
|
let slice_ref = &slice;
|
|
|
|
let _ = &slice_ref[..]; // Deref instead of slice
|
2020-12-31 16:10:13 +00:00
|
|
|
}
|