]> git.lizzy.rs Git - rust.git/blob - tests/ui/no_effect.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / no_effect.rs
1 #![feature(plugin, box_syntax, inclusive_range_syntax)]
2 #![plugin(clippy)]
3
4 #![deny(no_effect, unnecessary_operation)]
5 #![allow(dead_code)]
6 #![allow(path_statements)]
7 #![allow(deref_addrof)]
8 #![feature(untagged_unions)]
9
10 struct Unit;
11 struct Tuple(i32);
12 struct Struct {
13     field: i32
14 }
15 enum Enum {
16     Tuple(i32),
17     Struct { field: i32 },
18 }
19
20 union Union {
21     a: u8,
22     b: f64,
23 }
24
25 fn get_number() -> i32 { 0 }
26 fn get_struct() -> Struct { Struct { field: 0 } }
27
28 unsafe fn unsafe_fn() -> i32 { 0 }
29
30 fn main() {
31     let s = get_struct();
32     let s2 = get_struct();
33
34     0; //~ERROR statement with no effect
35     s2; //~ERROR statement with no effect
36     Unit; //~ERROR statement with no effect
37     Tuple(0); //~ERROR statement with no effect
38     Struct { field: 0 }; //~ERROR statement with no effect
39     Struct { ..s }; //~ERROR statement with no effect
40     Union { a: 0 }; //~ERROR statement with no effect
41     Enum::Tuple(0); //~ERROR statement with no effect
42     Enum::Struct { field: 0 }; //~ERROR statement with no effect
43     5 + 6; //~ERROR statement with no effect
44     *&42; //~ERROR statement with no effect
45     &6; //~ERROR statement with no effect
46     (5, 6, 7); //~ERROR statement with no effect
47     box 42; //~ERROR statement with no effect
48     ..; //~ERROR statement with no effect
49     5..; //~ERROR statement with no effect
50     ..5; //~ERROR statement with no effect
51     5..6; //~ERROR statement with no effect
52     5...6; //~ERROR statement with no effect
53     [42, 55]; //~ERROR statement with no effect
54     [42, 55][1]; //~ERROR statement with no effect
55     (42, 55).1; //~ERROR statement with no effect
56     [42; 55]; //~ERROR statement with no effect
57     [42; 55][13]; //~ERROR statement with no effect
58     let mut x = 0;
59     || x += 5; //~ERROR statement with no effect
60
61     // Do not warn
62     get_number();
63     unsafe { unsafe_fn() };
64
65     Tuple(get_number()); //~ERROR statement can be reduced
66     //~^HELP replace it with
67     //~|SUGGESTION get_number();
68     Struct { field: get_number() }; //~ERROR statement can be reduced
69     //~^HELP replace it with
70     //~|SUGGESTION get_number();
71     Struct { ..get_struct() }; //~ERROR statement can be reduced
72     //~^HELP replace it with
73     //~|SUGGESTION get_struct();
74     Enum::Tuple(get_number()); //~ERROR statement can be reduced
75     //~^HELP replace it with
76     //~|SUGGESTION get_number();
77     Enum::Struct { field: get_number() }; //~ERROR statement can be reduced
78     //~^HELP replace it with
79     //~|SUGGESTION get_number();
80     5 + get_number(); //~ERROR statement can be reduced
81     //~^HELP replace it with
82     //~|SUGGESTION 5;get_number();
83     *&get_number(); //~ERROR statement can be reduced
84     //~^HELP replace it with
85     //~|SUGGESTION get_number();
86     &get_number(); //~ERROR statement can be reduced
87     //~^HELP replace it with
88     //~|SUGGESTION get_number();
89     (5, 6, get_number()); //~ERROR statement can be reduced
90     //~^HELP replace it with
91     //~|SUGGESTION 5;6;get_number();
92     box get_number(); //~ERROR statement can be reduced
93     //~^HELP replace it with
94     //~|SUGGESTION get_number();
95     get_number()..; //~ERROR statement can be reduced
96     //~^HELP replace it with
97     //~|SUGGESTION get_number();
98     ..get_number(); //~ERROR statement can be reduced
99     //~^HELP replace it with
100     //~|SUGGESTION get_number();
101     5..get_number(); //~ERROR statement can be reduced
102     //~^HELP replace it with
103     //~|SUGGESTION 5;get_number();
104     [42, get_number()]; //~ERROR statement can be reduced
105     //~^HELP replace it with
106     //~|SUGGESTION 42;get_number();
107     [42, 55][get_number() as usize]; //~ERROR statement can be reduced
108     //~^HELP replace it with
109     //~|SUGGESTION [42, 55];get_number() as usize;
110     (42, get_number()).1; //~ERROR statement can be reduced
111     //~^HELP replace it with
112     //~|SUGGESTION 42;get_number();
113     [get_number(); 55]; //~ERROR statement can be reduced
114     //~^HELP replace it with
115     //~|SUGGESTION get_number();
116     [42; 55][get_number() as usize]; //~ERROR statement can be reduced
117     //~^HELP replace it with
118     //~|SUGGESTION [42; 55];get_number() as usize;
119     {get_number()}; //~ERROR statement can be reduced
120     //~^HELP replace it with
121     //~|SUGGESTION get_number();
122 }