about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/ignored_unit_patterns.rs
blob: 92feb9e6c2814d2530e5009cae09bf03f39f54ad (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
//@aux-build:proc_macro_derive.rs
#![warn(clippy::ignored_unit_patterns)]
#![allow(
    clippy::let_unit_value,
    clippy::redundant_pattern_matching,
    clippy::single_match,
    clippy::needless_borrow
)]

fn foo() -> Result<(), ()> {
    unimplemented!()
}

fn main() {
    match foo() {
        Ok(_) => {},  //~ ERROR: matching over `()` is more explicit
        Err(_) => {}, //~ ERROR: matching over `()` is more explicit
    }
    if let Ok(_) = foo() {}
    //~^ ERROR: matching over `()` is more explicit
    let _ = foo().map_err(|_| todo!());
    //~^ ERROR: matching over `()` is more explicit

    println!(
        "{:?}",
        match foo() {
            Ok(_) => {},
            //~^ ERROR: matching over `()` is more explicit
            Err(_) => {},
            //~^ ERROR: matching over `()` is more explicit
        }
    );
}

// ignored_unit_patterns in derive macro should be ok
#[derive(proc_macro_derive::StructIgnoredUnitPattern)]
pub struct B;

#[allow(unused)]
pub fn moo(_: ()) {
    let _ = foo().unwrap();
    //~^ ERROR: matching over `()` is more explicit
    let _: () = foo().unwrap();
    let _: () = ();
}

fn test_unit_ref_1() {
    let x: (usize, &&&&&()) = (1, &&&&&&());
    match x {
        (1, _) => unimplemented!(),
        //~^ ERROR: matching over `()` is more explicit
        _ => unimplemented!(),
    };
}

fn test_unit_ref_2(v: &[(usize, ())]) {
    for (x, _) in v {
        //~^ ERROR: matching over `()` is more explicit
        let _ = x;
    }
}