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