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)]
|
2022-01-03 14:25:00 -06:00
|
|
|
#![warn(clippy::redundant_slicing)]
|
|
|
|
|
2022-01-03 19:35:32 -06:00
|
|
|
use std::io::Read;
|
|
|
|
|
2022-01-03 14:25:00 -06:00
|
|
|
fn main() {
|
|
|
|
let slice: &[u32] = &[0];
|
|
|
|
let _ = slice; // Redundant slice
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
static S: &[u8] = &[0, 1, 2];
|
2022-02-13 17:43:19 -06:00
|
|
|
let _ = &mut &S[..]; // Ok, re-borrows slice
|
2022-01-03 14:25:00 -06: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
|
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
|
|
|
|
|
|
|
macro_rules! m {
|
|
|
|
($e:expr) => {
|
|
|
|
$e
|
|
|
|
};
|
|
|
|
}
|
|
|
|
let _ = slice;
|
|
|
|
|
|
|
|
macro_rules! m2 {
|
|
|
|
($e:expr) => {
|
|
|
|
&$e[..]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
let _ = m2!(slice); // Don't lint in a macro
|
|
|
|
|
|
|
|
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
|
2022-01-03 14:25:00 -06:00
|
|
|
}
|