rust-clippy/tests/ui/map_err.rs
Koichi ITO ae0216d557 Use the traits added to the Rust 2021 Edition prelude
Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
2022-05-12 00:38:11 +09:00

29 lines
616 B
Rust

#![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(())
}