3 #![deny(clippy::try_err)]
5 // Tests that a simple case works
6 // Should flag `Err(err)?`
7 pub fn basic_test() -> Result<i32, i32> {
9 // To avoid warnings during rustfix
16 // Tests that `.into()` is added when appropriate
17 pub fn into_test() -> Result<i32, i32> {
19 // To avoid warnings during rustfix
21 return Err(err.into());
26 // Tests that tries in general don't trigger the error
27 pub fn negative_test() -> Result<i32, i32> {
28 Ok(nested_error()? + 1)
31 // Tests that `.into()` isn't added when the error type
32 // matches the surrounding closure's return type, even
33 // when it doesn't match the surrounding function's.
34 pub fn closure_matches_test() -> Result<i32, i32> {
35 let res: Result<i32, i8> = Some(1)
39 // To avoid warnings during rustfix
51 // Tests that `.into()` isn't added when the error type
52 // doesn't match the surrounding closure's return type.
53 pub fn closure_into_test() -> Result<i32, i32> {
54 let res: Result<i32, i16> = Some(1)
58 // To avoid warnings during rustfix
60 return Err(err.into());
70 fn nested_error() -> Result<i32, i32> {
75 basic_test().unwrap();
77 negative_test().unwrap();
78 closure_matches_test().unwrap();
79 closure_into_test().unwrap();