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