about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/unit_arg_fixable.rs
blob: 03fd96efdf901b52e9b63af9cae90b02a2df9d31 (plain)
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
#![warn(clippy::unit_arg)]
#![allow(unused_must_use, unused_variables)]
#![allow(clippy::no_effect, clippy::uninlined_format_args)]

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);
}

fn bad() {
    foo({});
    //~^ unit_arg
    foo3({}, 2, 2);
    //~^ unit_arg
    taking_two_units({}, foo(0));
    //~^ unit_arg
    taking_three_units({}, foo(0), foo(1));
    //~^ unit_arg
}

fn taking_two_units(a: (), b: ()) {}
fn taking_three_units(a: (), b: (), c: ()) {}

fn main() {
    bad();
}

fn issue14857() {
    let fn_take_unit = |_: ()| {};
    fn_take_unit(Default::default());
    //~^ unit_arg

    fn some_other_fn(_: &i32) {}

    macro_rules! another_mac {
        () => {
            some_other_fn(&Default::default())
        };
        ($e:expr) => {
            some_other_fn(&$e)
        };
    }

    fn_take_unit(another_mac!());
    //~^ unit_arg
    fn_take_unit(another_mac!(1));
    //~^ unit_arg

    macro_rules! mac {
        (nondef $e:expr) => {
            $e
        };
        (empty_block) => {{}};
    }
    fn_take_unit(mac!(nondef Default::default()));
    //~^ unit_arg
    fn_take_unit(mac!(empty_block));
    //~^ unit_arg

    fn def<T: Default>() -> T {
        Default::default()
    }

    fn_take_unit(def());
    //~^ unit_arg
}