2023-07-27 06:40:22 -05:00
|
|
|
#![deny(clippy::index_refutable_slice)]
|
|
|
|
|
|
|
|
extern crate if_chain;
|
|
|
|
use if_chain::if_chain;
|
|
|
|
|
|
|
|
macro_rules! if_let_slice_macro {
|
|
|
|
() => {
|
|
|
|
// This would normally be linted
|
|
|
|
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
|
|
|
|
if let Some(slice) = slice {
|
|
|
|
println!("{}", slice[0]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Don't lint this
|
|
|
|
if_let_slice_macro!();
|
|
|
|
|
|
|
|
// Do lint this
|
|
|
|
if_chain! {
|
|
|
|
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
|
|
|
|
if let Some([slice_0, ..]) = slice;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this binding can be a slice pattern to avoid indexing
|
2023-07-27 06:40:22 -05:00
|
|
|
then {
|
|
|
|
println!("{}", slice_0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|