about summary refs log tree commit diff
path: root/tests/ui/lint/unused/closure-body-issue-136741.fixed
blob: 2ded52544b9929a5ab2b2d98ad94dd1de2bfcf20 (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
//@ run-rustfix
// ignore-tidy-linelength
#![deny(unused_parens)]
#![deny(unused_braces)]

fn long_expr_that_does_not_require_braces_long_expr_that_does_not_require_braces_long_expr_that_does_not_require_braces()
{}

fn func(f: impl FnOnce()) {
    f()
}

pub fn main() {
    let _closure = |x: i32, y: i32| { x * (x + (y * 2)) };
    let _ = || 0 == 0; //~ ERROR unnecessary parentheses around closure body
    let _ = (0..).find(|n| n % 2 == 0); //~ ERROR unnecessary parentheses around closure body
    let _ = (0..).find(|n| {n % 2 == 0});

    // multiple lines of code will not lint with braces
    let _ = (0..).find(|n| {
        n % 2 == 0
    });

    // multiple lines of code will lint with parentheses
    let _ = (0..).find(|n| n % 2 == 0);

    let _ = || {
        _ = 0;
        0 == 0 //~ ERROR unnecessary parentheses around block return value
    };

    // long expressions will not lint with braces
    func(|| {
        long_expr_that_does_not_require_braces_long_expr_that_does_not_require_braces_long_expr_that_does_not_require_braces()
    })
}