]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/no_effect.rs
Auto merge of #97944 - nikic:freebsd-update, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / no_effect.rs
1 #![feature(box_syntax, fn_traits, unboxed_closures)]
2 #![warn(clippy::no_effect_underscore_binding)]
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 struct GreetStruct1;
62
63 impl FnOnce<(&str,)> for GreetStruct1 {
64     type Output = ();
65
66     extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
67         println!("hello {}", who);
68     }
69 }
70
71 struct GreetStruct2();
72
73 impl FnOnce<(&str,)> for GreetStruct2 {
74     type Output = ();
75
76     extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
77         println!("hello {}", who);
78     }
79 }
80
81 struct GreetStruct3;
82
83 impl FnOnce<(&str,)> for GreetStruct3 {
84     type Output = ();
85
86     extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
87         println!("hello {}", who);
88     }
89 }
90
91 fn main() {
92     let s = get_struct();
93     let s2 = get_struct();
94
95     0;
96     s2;
97     Unit;
98     Tuple(0);
99     Struct { field: 0 };
100     Struct { ..s };
101     Union { a: 0 };
102     Enum::Tuple(0);
103     Enum::Struct { field: 0 };
104     5 + 6;
105     *&42;
106     &6;
107     (5, 6, 7);
108     box 42;
109     ..;
110     5..;
111     ..5;
112     5..6;
113     5..=6;
114     [42, 55];
115     [42, 55][1];
116     (42, 55).1;
117     [42; 55];
118     [42; 55][13];
119     let mut x = 0;
120     || x += 5;
121     let s: String = "foo".into();
122     FooString { s: s };
123     let _unused = 1;
124     let _penguin = || println!("Some helpful closure");
125     let _duck = Struct { field: 0 };
126     let _cat = [2, 4, 6, 8][2];
127
128     #[allow(clippy::no_effect)]
129     0;
130
131     // Do not warn
132     get_number();
133     unsafe { unsafe_fn() };
134     let _used = get_struct();
135     let _x = vec![1];
136     DropUnit;
137     DropStruct { field: 0 };
138     DropTuple(0);
139     DropEnum::Tuple(0);
140     DropEnum::Struct { field: 0 };
141     GreetStruct1("world");
142     GreetStruct2()("world");
143     GreetStruct3 {}("world");
144 }