]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/map_err.rs
Auto merge of #101969 - reez12g:issue-101306, r=reez12g
[rust.git] / src / tools / clippy / tests / ui / map_err.rs
1 #![warn(clippy::map_err_ignore)]
2 #![allow(clippy::unnecessary_wraps)]
3 use std::error::Error;
4 use std::fmt;
5
6 #[derive(Debug)]
7 enum Errors {
8     Ignored,
9 }
10
11 impl Error for Errors {}
12
13 impl fmt::Display for Errors {
14     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15         write!(f, "Error")
16     }
17 }
18
19 fn main() -> Result<(), Errors> {
20     let x = u32::try_from(-123_i32);
21
22     println!("{:?}", x.map_err(|_| Errors::Ignored));
23
24     // Should not warn you because you explicitly ignore the parameter
25     // using a named wildcard value
26     println!("{:?}", x.map_err(|_foo| Errors::Ignored));
27
28     Ok(())
29 }