]> git.lizzy.rs Git - rust.git/blob - tests/ui/unit_arg.rs
Allow this lint on lint tests
[rust.git] / tests / ui / unit_arg.rs
1 #![warn(clippy::unit_arg)]
2 #![allow(
3     clippy::no_effect,
4     unused_must_use,
5     unused_variables,
6     clippy::unused_unit,
7     clippy::unnecessary_wrap,
8     clippy::or_fun_call
9 )]
10
11 use std::fmt::Debug;
12
13 fn foo<T: Debug>(t: T) {
14     println!("{:?}", t);
15 }
16
17 fn foo3<T1: Debug, T2: Debug, T3: Debug>(t1: T1, t2: T2, t3: T3) {
18     println!("{:?}, {:?}, {:?}", t1, t2, t3);
19 }
20
21 struct Bar;
22
23 impl Bar {
24     fn bar<T: Debug>(&self, t: T) {
25         println!("{:?}", t);
26     }
27 }
28
29 fn bad() {
30     foo({
31         1;
32     });
33     foo(foo(1));
34     foo({
35         foo(1);
36         foo(2);
37     });
38     let b = Bar;
39     b.bar({
40         1;
41     });
42     taking_multiple_units(foo(0), foo(1));
43     taking_multiple_units(foo(0), {
44         foo(1);
45         foo(2);
46     });
47     taking_multiple_units(
48         {
49             foo(0);
50             foo(1);
51         },
52         {
53             foo(2);
54             foo(3);
55         },
56     );
57     // here Some(foo(2)) isn't the top level statement expression, wrap the suggestion in a block
58     None.or(Some(foo(2)));
59     // in this case, the suggestion can be inlined, no need for a surrounding block
60     // foo(()); foo(()) instead of { foo(()); foo(()) }
61     foo(foo(()))
62 }
63
64 fn ok() {
65     foo(());
66     foo(1);
67     foo({ 1 });
68     foo3("a", 3, vec![3]);
69     let b = Bar;
70     b.bar({ 1 });
71     b.bar(());
72     question_mark();
73 }
74
75 fn question_mark() -> Result<(), ()> {
76     Ok(Ok(())?)?;
77     Ok(Ok(()))??;
78     Ok(())
79 }
80
81 #[allow(dead_code)]
82 mod issue_2945 {
83     fn unit_fn() -> Result<(), i32> {
84         Ok(())
85     }
86
87     fn fallible() -> Result<(), i32> {
88         Ok(unit_fn()?)
89     }
90 }
91
92 #[allow(dead_code)]
93 fn returning_expr() -> Option<()> {
94     Some(foo(1))
95 }
96
97 fn taking_multiple_units(a: (), b: ()) {}
98
99 fn main() {
100     bad();
101     ok();
102 }