]> git.lizzy.rs Git - rust.git/blob - tests/ui/unit_arg.rs
Update test files
[rust.git] / 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     foo({
25         1;
26     });
27     foo(foo(1));
28     foo({
29         foo(1);
30         foo(2);
31     });
32     foo3({}, 2, 2);
33     let b = Bar;
34     b.bar({
35         1;
36     });
37     taking_multiple_units(foo(0), foo(1));
38     taking_multiple_units(foo(0), {
39         foo(1);
40         foo(2);
41     });
42     taking_multiple_units(
43         {
44             foo(0);
45             foo(1);
46         },
47         {
48             foo(2);
49             foo(3);
50         },
51     );
52 }
53
54 fn ok() {
55     foo(());
56     foo(1);
57     foo({ 1 });
58     foo3("a", 3, vec![3]);
59     let b = Bar;
60     b.bar({ 1 });
61     b.bar(());
62     question_mark();
63 }
64
65 fn question_mark() -> Result<(), ()> {
66     Ok(Ok(())?)?;
67     Ok(Ok(()))??;
68     Ok(())
69 }
70
71 #[allow(dead_code)]
72 mod issue_2945 {
73     fn unit_fn() -> Result<(), i32> {
74         Ok(())
75     }
76
77     fn fallible() -> Result<(), i32> {
78         Ok(unit_fn()?)
79     }
80 }
81
82 #[allow(dead_code)]
83 fn returning_expr() -> Option<()> {
84     Some(foo(1))
85 }
86
87 fn taking_multiple_units(a: (), b: ()) {}
88
89 fn main() {
90     bad();
91     ok();
92 }