summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/numbered_fields.fixed
blob: 7f0a6f8e5447752e74eed3ca897a1fbbfe6c09dd (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
#![warn(clippy::init_numbered_fields)]
#![allow(unused_tuple_struct_fields)]

#[derive(Default)]
struct TupleStruct(u32, u32, u8);

// This shouldn't lint because it's in a macro
macro_rules! tuple_struct_init {
    () => {
        TupleStruct { 0: 0, 1: 1, 2: 2 }
    };
}

fn main() {
    let tuple_struct = TupleStruct::default();

    // This should lint
    let _ = TupleStruct(1u32, 42, 23u8);

    // This should also lint and order the fields correctly
    let _ = TupleStruct(1u32, 3u32, 2u8);

    // Ok because of default initializer
    let _ = TupleStruct { 0: 42, ..tuple_struct };

    let _ = TupleStruct {
        1: 23,
        ..TupleStruct::default()
    };

    // Ok because it's in macro
    let _ = tuple_struct_init!();

    type Alias = TupleStruct;

    // Aliases can't be tuple constructed #8638
    let _ = Alias { 0: 0, 1: 1, 2: 2 };
}