2023-04-20 09:37:15 -05:00
|
|
|
//@run-rustfix
|
2022-01-03 14:25:00 -06:00
|
|
|
|
2022-01-11 11:41:15 -06:00
|
|
|
#![allow(unused, clippy::deref_by_slicing)]
|
2020-12-31 10:10:13 -06:00
|
|
|
#![warn(clippy::redundant_slicing)]
|
|
|
|
|
2022-01-03 19:35:32 -06:00
|
|
|
use std::io::Read;
|
|
|
|
|
2020-12-31 10:10:13 -06:00
|
|
|
fn main() {
|
2021-03-25 21:30:14 -05:00
|
|
|
let slice: &[u32] = &[0];
|
2022-01-03 14:25:00 -06:00
|
|
|
let _ = &slice[..]; // Redundant slice
|
2020-12-31 10:10:13 -06:00
|
|
|
|
|
|
|
let v = vec![0];
|
2022-01-11 11:41:15 -06:00
|
|
|
let _ = &v[..]; // Ok, results in `&[_]`
|
2022-01-03 14:25:00 -06:00
|
|
|
let _ = &(&*v)[..]; // Outer borrow is redundant
|
2021-03-25 21:30:14 -05:00
|
|
|
|
|
|
|
static S: &[u8] = &[0, 1, 2];
|
2022-02-13 17:43:19 -06:00
|
|
|
let _ = &mut &S[..]; // Ok, re-borrows slice
|
2021-03-25 21:30:14 -05:00
|
|
|
|
|
|
|
let mut vec = vec![0];
|
2022-01-11 11:41:15 -06:00
|
|
|
let mut_slice = &mut vec[..]; // Ok, results in `&mut [_]`
|
2022-02-13 17:43:19 -06:00
|
|
|
let _ = &mut mut_slice[..]; // Ok, re-borrows slice
|
2021-03-25 21:30:14 -05:00
|
|
|
|
2022-01-03 14:25:00 -06:00
|
|
|
let ref_vec = &vec;
|
2022-01-11 11:41:15 -06:00
|
|
|
let _ = &ref_vec[..]; // Ok, results in `&[_]`
|
2022-01-03 14:25:00 -06:00
|
|
|
|
2021-03-25 21:30:14 -05: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 14:25:00 -06:00
|
|
|
|
|
|
|
let slice_ref = &slice;
|
2022-02-13 17:43:19 -06:00
|
|
|
let _ = &slice_ref[..]; // Ok, derefs slice
|
2022-01-03 19:35:32 -06:00
|
|
|
|
|
|
|
// Issue #7972
|
|
|
|
let bytes: &[u8] = &[];
|
2022-02-13 17:43:19 -06:00
|
|
|
let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Ok, re-borrows slice
|
2020-12-31 10:10:13 -06:00
|
|
|
}
|