2 // aux-build:macro_rules.rs
4 #![deny(clippy::try_err)]
7 extern crate macro_rules;
9 // Tests that a simple case works
10 // Should flag `Err(err)?`
11 pub fn basic_test() -> Result<i32, i32> {
13 // To avoid warnings during rustfix
20 // Tests that `.into()` is added when appropriate
21 pub fn into_test() -> Result<i32, i32> {
23 // To avoid warnings during rustfix
25 return Err(err.into());
30 // Tests that tries in general don't trigger the error
31 pub fn negative_test() -> Result<i32, i32> {
32 Ok(nested_error()? + 1)
35 // Tests that `.into()` isn't added when the error type
36 // matches the surrounding closure's return type, even
37 // when it doesn't match the surrounding function's.
38 pub fn closure_matches_test() -> Result<i32, i32> {
39 let res: Result<i32, i8> = Some(1)
43 // To avoid warnings during rustfix
55 // Tests that `.into()` isn't added when the error type
56 // doesn't match the surrounding closure's return type.
57 pub fn closure_into_test() -> Result<i32, i32> {
58 let res: Result<i32, i16> = Some(1)
62 // To avoid warnings during rustfix
64 return Err(err.into());
74 fn nested_error() -> Result<i32, i32> {
79 basic_test().unwrap();
81 negative_test().unwrap();
82 closure_matches_test().unwrap();
83 closure_into_test().unwrap();
85 // We don't want to lint in external macros
91 String::from("aasdfasdfasdfa")
101 pub fn macro_inside(fail: bool) -> Result<i32, String> {