summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.rs
blob: 086331af6b5673fed75858630f90677e24f5e22c (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#![warn(clippy::rest_pat_in_fully_bound_structs)]

struct A {
    a: i32,
    b: i64,
    c: &'static str,
}

macro_rules! foo {
    ($param:expr) => {
        match $param {
            A { a: 0, b: 0, c: "", .. } => {},
            _ => {},
        }
    };
}

fn main() {
    let a_struct = A { a: 5, b: 42, c: "A" };

    match a_struct {
        A { a: 5, b: 42, c: "", .. } => {}, // Lint
        A { a: 0, b: 0, c: "", .. } => {},  // Lint
        _ => {},
    }

    match a_struct {
        A { a: 5, b: 42, .. } => {},
        A { a: 0, b: 0, c: "", .. } => {}, // Lint
        _ => {},
    }

    // No lint
    match a_struct {
        A { a: 5, .. } => {},
        A { a: 0, b: 0, .. } => {},
        _ => {},
    }

    // No lint
    foo!(a_struct);

    #[non_exhaustive]
    struct B {
        a: u32,
        b: u32,
        c: u64,
    }

    let b_struct = B { a: 5, b: 42, c: 342 };

    match b_struct {
        B { a: 5, b: 42, .. } => {},
        B { a: 0, b: 0, c: 128, .. } => {}, // No Lint
        _ => {},
    }
}