2020-09-24 12:49:22 +00:00
|
|
|
#![warn(clippy::map_err_ignore)]
|
2020-11-23 12:51:04 +00:00
|
|
|
#![allow(clippy::unnecessary_wraps)]
|
2020-09-24 12:49:22 +00: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 19:32:12 +00:00
|
|
|
//~^ ERROR: `map_err(|_|...` wildcard pattern discards the original error
|
2020-09-24 12:49:22 +00:00
|
|
|
|
2020-12-06 14:01:03 +00: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 12:49:22 +00:00
|
|
|
Ok(())
|
|
|
|
}
|