]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/no_effect.rs
Merge commit '7c7683c8efe447b251d6c5ca6cce51233060f6e8' into clippyup
[rust.git] / src / tools / clippy / tests / ui / no_effect.rs
1 #![feature(box_syntax)]
2 #![warn(clippy::no_effect)]
3 #![allow(dead_code)]
4 #![allow(path_statements)]
5 #![allow(clippy::deref_addrof)]
6 #![allow(clippy::redundant_field_names)]
7 #![feature(untagged_unions)]
8
9 struct Unit;
10 struct Tuple(i32);
11 struct Struct {
12     field: i32,
13 }
14 enum Enum {
15     Tuple(i32),
16     Struct { field: i32 },
17 }
18 struct DropUnit;
19 impl Drop for DropUnit {
20     fn drop(&mut self) {}
21 }
22 struct DropStruct {
23     field: i32,
24 }
25 impl Drop for DropStruct {
26     fn drop(&mut self) {}
27 }
28 struct DropTuple(i32);
29 impl Drop for DropTuple {
30     fn drop(&mut self) {}
31 }
32 enum DropEnum {
33     Tuple(i32),
34     Struct { field: i32 },
35 }
36 impl Drop for DropEnum {
37     fn drop(&mut self) {}
38 }
39 struct FooString {
40     s: String,
41 }
42 union Union {
43     a: u8,
44     b: f64,
45 }
46
47 fn get_number() -> i32 {
48     0
49 }
50 fn get_struct() -> Struct {
51     Struct { field: 0 }
52 }
53 fn get_drop_struct() -> DropStruct {
54     DropStruct { field: 0 }
55 }
56
57 unsafe fn unsafe_fn() -> i32 {
58     0
59 }
60
61 fn main() {
62     let s = get_struct();
63     let s2 = get_struct();
64
65     0;
66     s2;
67     Unit;
68     Tuple(0);
69     Struct { field: 0 };
70     Struct { ..s };
71     Union { a: 0 };
72     Enum::Tuple(0);
73     Enum::Struct { field: 0 };
74     5 + 6;
75     *&42;
76     &6;
77     (5, 6, 7);
78     box 42;
79     ..;
80     5..;
81     ..5;
82     5..6;
83     5..=6;
84     [42, 55];
85     [42, 55][1];
86     (42, 55).1;
87     [42; 55];
88     [42; 55][13];
89     let mut x = 0;
90     || x += 5;
91     let s: String = "foo".into();
92     FooString { s: s };
93
94     // Do not warn
95     get_number();
96     unsafe { unsafe_fn() };
97     DropUnit;
98     DropStruct { field: 0 };
99     DropTuple(0);
100     DropEnum::Tuple(0);
101     DropEnum::Struct { field: 0 };
102 }