summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/needless_update.rs
blob: 7c59abf07aba9f2b7c0e2f1ecc745f6d433ae8da (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
#![warn(clippy::needless_update)]
#![allow(clippy::no_effect, clippy::unnecessary_struct_initialization)]

struct S {
    pub a: i32,
    pub b: i32,
}

#[non_exhaustive]
struct T {
    pub x: i32,
    pub y: i32,
}

fn main() {
    let base = S { a: 0, b: 0 };
    S { ..base }; // no error
    S { a: 1, ..base }; // no error
    S { a: 1, b: 1, ..base };
    //~^ ERROR: struct update has no effect, all the fields in the struct have already bee
    //~| NOTE: `-D clippy::needless-update` implied by `-D warnings`

    let base = T { x: 0, y: 0 };
    T { ..base }; // no error
    T { x: 1, ..base }; // no error
    T { x: 1, y: 1, ..base }; // no error
}