summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/double_parens.rs
blob: ab1459eed48bc1265345cc978f01ce7c22747220 (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
#![warn(clippy::double_parens)]
#![allow(dead_code, clippy::eq_op)]
#![feature(custom_inner_attributes)]
#![rustfmt::skip]

fn dummy_fn<T>(_: T) {}

struct DummyStruct;

impl DummyStruct {
    fn dummy_method<T>(self, _: T) {}
}

fn simple_double_parens() -> i32 {
    ((0))
    //~^ ERROR: consider removing unnecessary double parentheses
    //~| NOTE: `-D clippy::double-parens` implied by `-D warnings`
}

fn fn_double_parens() {
    dummy_fn((0));
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn method_double_parens(x: DummyStruct) {
    x.dummy_method((0));
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn tuple_double_parens() -> (i32, i32) {
    ((1, 2))
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn unit_double_parens() {
    (())
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn fn_tuple_ok() {
    dummy_fn((1, 2));
}

fn method_tuple_ok(x: DummyStruct) {
    x.dummy_method((1, 2));
}

fn fn_unit_ok() {
    dummy_fn(());
}

fn method_unit_ok(x: DummyStruct) {
    x.dummy_method(());
}

// Issue #3206
fn inside_macro() {
    assert_eq!((1, 2), (1, 2), "Error");
    assert_eq!(((1, 2)), (1, 2), "Error");
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn main() {}