]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/no_effect.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[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, path_statements)]
4 #![allow(clippy::deref_addrof, clippy::redundant_field_names, clippy::uninlined_format_args)]
5
6 struct Unit;
7 struct Tuple(i32);
8 struct Struct {
9     field: i32,
10 }
11 enum Enum {
12     Tuple(i32),
13     Struct { field: i32 },
14 }
15 struct DropUnit;
16 impl Drop for DropUnit {
17     fn drop(&mut self) {}
18 }
19 struct DropStruct {
20     field: i32,
21 }
22 impl Drop for DropStruct {
23     fn drop(&mut self) {}
24 }
25 struct DropTuple(i32);
26 impl Drop for DropTuple {
27     fn drop(&mut self) {}
28 }
29 enum DropEnum {
30     Tuple(i32),
31     Struct { field: i32 },
32 }
33 impl Drop for DropEnum {
34     fn drop(&mut self) {}
35 }
36 struct FooString {
37     s: String,
38 }
39 union Union {
40     a: u8,
41     b: f64,
42 }
43
44 fn get_number() -> i32 {
45     0
46 }
47 fn get_struct() -> Struct {
48     Struct { field: 0 }
49 }
50 fn get_drop_struct() -> DropStruct {
51     DropStruct { field: 0 }
52 }
53
54 unsafe fn unsafe_fn() -> i32 {
55     0
56 }
57
58 struct GreetStruct1;
59
60 impl FnOnce<(&str,)> for GreetStruct1 {
61     type Output = ();
62
63     extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
64         println!("hello {}", who);
65     }
66 }
67
68 struct GreetStruct2();
69
70 impl FnOnce<(&str,)> for GreetStruct2 {
71     type Output = ();
72
73     extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
74         println!("hello {}", who);
75     }
76 }
77
78 struct GreetStruct3;
79
80 impl FnOnce<(&str,)> for GreetStruct3 {
81     type Output = ();
82
83     extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
84         println!("hello {}", who);
85     }
86 }
87
88 fn main() {
89     let s = get_struct();
90     let s2 = get_struct();
91
92     0;
93     s2;
94     Unit;
95     Tuple(0);
96     Struct { field: 0 };
97     Struct { ..s };
98     Union { a: 0 };
99     Enum::Tuple(0);
100     Enum::Struct { field: 0 };
101     5 + 6;
102     *&42;
103     &6;
104     (5, 6, 7);
105     box 42;
106     ..;
107     5..;
108     ..5;
109     5..6;
110     5..=6;
111     [42, 55];
112     [42, 55][1];
113     (42, 55).1;
114     [42; 55];
115     [42; 55][13];
116     let mut x = 0;
117     || x += 5;
118     let s: String = "foo".into();
119     FooString { s: s };
120     let _unused = 1;
121     let _penguin = || println!("Some helpful closure");
122     let _duck = Struct { field: 0 };
123     let _cat = [2, 4, 6, 8][2];
124
125     #[allow(clippy::no_effect)]
126     0;
127
128     // Do not warn
129     get_number();
130     unsafe { unsafe_fn() };
131     let _used = get_struct();
132     let _x = vec![1];
133     DropUnit;
134     DropStruct { field: 0 };
135     DropTuple(0);
136     DropEnum::Tuple(0);
137     DropEnum::Struct { field: 0 };
138     GreetStruct1("world");
139     GreetStruct2()("world");
140     GreetStruct3 {}("world");
141 }