summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs
blob: 406e82083f88f2e4058ab23e6c66eb233b9614a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#![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) = slice;
        then {
            println!("{}", slice[0]);
        }
    }
}