Fix incorrect suggestion for try_err lint when Err arg is itself a macro
This commit is contained in:
parent
f83762b79c
commit
83e75f9207
4 changed files with 58 additions and 8 deletions
|
|
@ -88,8 +88,26 @@ macro_rules! try_validation {
|
|||
}};
|
||||
}
|
||||
|
||||
macro_rules! ret_one {
|
||||
() => {
|
||||
1
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! try_validation_in_macro {
|
||||
($e: expr) => {{
|
||||
match $e {
|
||||
Ok(_) => 0,
|
||||
Err(_) => return Err(ret_one!()),
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
fn calling_macro() -> Result<i32, i32> {
|
||||
// macro
|
||||
try_validation!(Ok::<_, i32>(5));
|
||||
// `Err` arg is another macro
|
||||
try_validation_in_macro!(Ok::<_, i32>(5));
|
||||
Ok(5)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,8 +88,26 @@ macro_rules! try_validation {
|
|||
}};
|
||||
}
|
||||
|
||||
macro_rules! ret_one {
|
||||
() => {
|
||||
1
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! try_validation_in_macro {
|
||||
($e: expr) => {{
|
||||
match $e {
|
||||
Ok(_) => 0,
|
||||
Err(_) => Err(ret_one!())?,
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
fn calling_macro() -> Result<i32, i32> {
|
||||
// macro
|
||||
try_validation!(Ok::<_, i32>(5));
|
||||
// `Err` arg is another macro
|
||||
try_validation_in_macro!(Ok::<_, i32>(5));
|
||||
Ok(5)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,28 +40,39 @@ LL | try_validation!(Ok::<_, i32>(5));
|
|||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: returning an `Err(_)` with the `?` operator
|
||||
--> $DIR/try_err.rs:122:9
|
||||
--> $DIR/try_err.rs:101:23
|
||||
|
|
||||
LL | Err(_) => Err(ret_one!())?,
|
||||
| ^^^^^^^^^^^^^^^^ help: try this: `return Err(ret_one!())`
|
||||
...
|
||||
LL | try_validation_in_macro!(Ok::<_, i32>(5));
|
||||
| ------------------------------------------ in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: returning an `Err(_)` with the `?` operator
|
||||
--> $DIR/try_err.rs:140:9
|
||||
|
|
||||
LL | Err(foo!())?;
|
||||
| ^^^^^^^^^^^^ help: try this: `return Err(foo!())`
|
||||
|
||||
error: returning an `Err(_)` with the `?` operator
|
||||
--> $DIR/try_err.rs:129:9
|
||||
--> $DIR/try_err.rs:147:9
|
||||
|
|
||||
LL | Err(io::ErrorKind::WriteZero)?
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))`
|
||||
|
||||
error: returning an `Err(_)` with the `?` operator
|
||||
--> $DIR/try_err.rs:131:9
|
||||
--> $DIR/try_err.rs:149:9
|
||||
|
|
||||
LL | Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))?
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))`
|
||||
|
||||
error: returning an `Err(_)` with the `?` operator
|
||||
--> $DIR/try_err.rs:139:9
|
||||
--> $DIR/try_err.rs:157:9
|
||||
|
|
||||
LL | Err(io::ErrorKind::NotFound)?
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue