2020-09-24 07:49:22 -05:00
|
|
|
#![warn(clippy::map_err_ignore)]
|
2020-11-23 06:51:04 -06:00
|
|
|
#![allow(clippy::unnecessary_wraps)]
|
2020-09-24 07:49:22 -05:00
|
|
|
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));
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: `map_err(|_|...` wildcard pattern discards the original error
|
2020-09-24 07:49:22 -05:00
|
|
|
|
2020-12-06 08:01:03 -06:00
|
|
|
// Should not warn you because you explicitly ignore the parameter
|
|
|
|
// using a named wildcard value
|
|
|
|
println!("{:?}", x.map_err(|_foo| Errors::Ignored));
|
|
|
|
|
2020-09-24 07:49:22 -05:00
|
|
|
Ok(())
|
|
|
|
}
|