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