/
unit_arg.fixed
79 lines (66 loc) · 1.2 KB
/
unit_arg.fixed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// run-rustfix
#![warn(clippy::unit_arg)]
#![allow(clippy::no_effect, unused_must_use, unused_variables)]
use std::fmt::Debug;
fn foo<T: Debug>(t: T) {
println!("{:?}", t);
}
fn foo3<T1: Debug, T2: Debug, T3: Debug>(t1: T1, t2: T2, t3: T3) {
println!("{:?}, {:?}, {:?}", t1, t2, t3);
}
struct Bar;
impl Bar {
fn bar<T: Debug>(&self, t: T) {
println!("{:?}", t);
}
}
fn bad() {
{}; foo(());
{
1;
}; foo(());
foo(1); foo(());
{
foo(1);
foo(2);
}; foo(());
{}; foo3((), 2, 2);
let b = Bar;
{
1;
}; b.bar(());
foo(0); foo(1); taking_multiple_units((), ());
}
fn ok() {
foo(());
foo(1);
foo({ 1 });
foo3("a", 3, vec![3]);
let b = Bar;
b.bar({ 1 });
b.bar(());
question_mark();
}
fn question_mark() -> Result<(), ()> {
Ok(Ok(())?)?;
Ok(Ok(()))??;
Ok(())
}
#[allow(dead_code)]
mod issue_2945 {
fn unit_fn() -> Result<(), i32> {
Ok(())
}
fn fallible() -> Result<(), i32> {
Ok(unit_fn()?)
}
}
#[allow(dead_code)]
fn returning_expr() -> Option<()> {
foo(1); Some(())
}
fn taking_multiple_units(a: (), b: ()) {}
fn main() {
bad();
ok();
}