diff options
Diffstat (limited to 'src/tools/clippy/tests/ui/map_err.rs')
-rw-r--r-- | src/tools/clippy/tests/ui/map_err.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/map_err.rs b/src/tools/clippy/tests/ui/map_err.rs new file mode 100644 index 000000000..bb35ab1a1 --- /dev/null +++ b/src/tools/clippy/tests/ui/map_err.rs @@ -0,0 +1,29 @@ +#![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)); + + // Should not warn you because you explicitly ignore the parameter + // using a named wildcard value + println!("{:?}", x.map_err(|_foo| Errors::Ignored)); + + Ok(()) +} |