]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/unit_arg.rs
Auto merge of #76378 - petrochenkov:lldtest, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / unit_arg.rs
1 #![warn(clippy::unit_arg)]
2 #![allow(clippy::no_effect, unused_must_use, unused_variables)]
3
4 use std::fmt::Debug;
5
6 fn foo<T: Debug>(t: T) {
7     println!("{:?}", t);
8 }
9
10 fn foo3<T1: Debug, T2: Debug, T3: Debug>(t1: T1, t2: T2, t3: T3) {
11     println!("{:?}, {:?}, {:?}", t1, t2, t3);
12 }
13
14 struct Bar;
15
16 impl Bar {
17     fn bar<T: Debug>(&self, t: T) {
18         println!("{:?}", t);
19     }
20 }
21
22 fn bad() {
23     foo({
24         1;
25     });
26     foo(foo(1));
27     foo({
28         foo(1);
29         foo(2);
30     });
31     let b = Bar;
32     b.bar({
33         1;
34     });
35     taking_multiple_units(foo(0), foo(1));
36     taking_multiple_units(foo(0), {
37         foo(1);
38         foo(2);
39     });
40     taking_multiple_units(
41         {
42             foo(0);
43             foo(1);
44         },
45         {
46             foo(2);
47             foo(3);
48         },
49     );
50 }
51
52 fn ok() {
53     foo(());
54     foo(1);
55     foo({ 1 });
56     foo3("a", 3, vec![3]);
57     let b = Bar;
58     b.bar({ 1 });
59     b.bar(());
60     question_mark();
61 }
62
63 fn question_mark() -> Result<(), ()> {
64     Ok(Ok(())?)?;
65     Ok(Ok(()))??;
66     Ok(())
67 }
68
69 #[allow(dead_code)]
70 mod issue_2945 {
71     fn unit_fn() -> Result<(), i32> {
72         Ok(())
73     }
74
75     fn fallible() -> Result<(), i32> {
76         Ok(unit_fn()?)
77     }
78 }
79
80 #[allow(dead_code)]
81 fn returning_expr() -> Option<()> {
82     Some(foo(1))
83 }
84
85 fn taking_multiple_units(a: (), b: ()) {}
86
87 fn main() {
88     bad();
89     ok();
90 }