about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/map_err.rs
blob: 0f0c8f6c71cf8b631a63624fbbfaab0580aa29cb (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
#![warn(clippy::map_err_ignore)]
#![allow(clippy::unnecessary_wraps)]
use std::error::Error;
use std::fmt;

#[derive(Debug)]
enum Errors {
    Ignored,
}

impl Error for Errors {}

impl fmt::Display for Errors {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "Error")
    }
}

fn main() -> Result<(), Errors> {
    let x = u32::try_from(-123_i32);

    println!("{:?}", x.map_err(|_| Errors::Ignored));
    //~^ map_err_ignore

    // Should not warn you because you explicitly ignore the parameter
    // using a named wildcard value
    println!("{:?}", x.map_err(|_foo| Errors::Ignored));

    Ok(())
}