2 // aux-build:macro_rules.rs
4 #![deny(clippy::try_err)]
7 extern crate macro_rules;
12 // Tests that a simple case works
13 // Should flag `Err(err)?`
14 pub fn basic_test() -> Result<i32, i32> {
16 // To avoid warnings during rustfix
23 // Tests that `.into()` is added when appropriate
24 pub fn into_test() -> Result<i32, i32> {
26 // To avoid warnings during rustfix
28 return Err(err.into());
33 // Tests that tries in general don't trigger the error
34 pub fn negative_test() -> Result<i32, i32> {
35 Ok(nested_error()? + 1)
38 // Tests that `.into()` isn't added when the error type
39 // matches the surrounding closure's return type, even
40 // when it doesn't match the surrounding function's.
41 pub fn closure_matches_test() -> Result<i32, i32> {
42 let res: Result<i32, i8> = Some(1)
46 // To avoid warnings during rustfix
58 // Tests that `.into()` isn't added when the error type
59 // doesn't match the surrounding closure's return type.
60 pub fn closure_into_test() -> Result<i32, i32> {
61 let res: Result<i32, i16> = Some(1)
65 // To avoid warnings during rustfix
67 return Err(err.into());
77 fn nested_error() -> Result<i32, i32> {
82 basic_test().unwrap();
84 negative_test().unwrap();
85 closure_matches_test().unwrap();
86 closure_into_test().unwrap();
88 // We don't want to lint in external macros
94 String::from("aasdfasdfasdfa")
104 pub fn macro_inside(fail: bool) -> Result<i32, String> {
111 pub fn poll_write(n: usize) -> Poll<io::Result<usize>> {
113 return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))
115 return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))
121 pub fn poll_next(ready: bool) -> Poll<Option<io::Result<()>>> {
123 return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))