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