Auto merge of #13107 - yaxum62:i5757, r=xFrednet
Add test for `try_err` lint within try blocks.
Fixes #5757
Turns out the current `try_err` implementation already skips expressions inside of a try block.
When inside of a try block, `Err(_)?` is desugared to a `break` instead of normal `return` . This makes `find_return_type()` function at [this line](eb4d88e690/clippy_lints/src/matches/try_err.rs (L29)
) always returns `None` and skips the check.
I just added a test case for try block.
changelog: none
This commit is contained in:
commit
0347280d5f
@ -1,5 +1,5 @@
|
||||
//@aux-build:proc_macros.rs
|
||||
|
||||
#![feature(try_blocks)]
|
||||
#![deny(clippy::try_err)]
|
||||
#![allow(
|
||||
clippy::unnecessary_wraps,
|
||||
@ -152,3 +152,11 @@ pub fn try_return(x: bool) -> Result<i32, i32> {
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
// Test that the lint is suppressed in try block.
|
||||
pub fn try_block() -> Result<(), i32> {
|
||||
let _: Result<_, i32> = try {
|
||||
Err(1)?;
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
//@aux-build:proc_macros.rs
|
||||
|
||||
#![feature(try_blocks)]
|
||||
#![deny(clippy::try_err)]
|
||||
#![allow(
|
||||
clippy::unnecessary_wraps,
|
||||
@ -152,3 +152,11 @@ pub fn try_return(x: bool) -> Result<i32, i32> {
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
// Test that the lint is suppressed in try block.
|
||||
pub fn try_block() -> Result<(), i32> {
|
||||
let _: Result<_, i32> = try {
|
||||
Err(1)?;
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user