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