diff options
| author | bors <bors@rust-lang.org> | 2024-08-03 08:25:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-03 08:25:37 +0000 |
| commit | 0347280d5f4e672542d9f87f40798279cf9dcfe4 (patch) | |
| tree | ab7ff8ac1788f25631c1b9b129039e12c850a7df | |
| parent | 1ea827fa03c44d4d4befcbee9e8465bcbdbeae03 (diff) | |
| parent | 1821defc39d410b3f761dbc0bae45e7ac1e6d585 (diff) | |
| download | rust-0347280d5f4e672542d9f87f40798279cf9dcfe4.tar.gz rust-0347280d5f4e672542d9f87f40798279cf9dcfe4.zip | |
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](https://github.com/rust-lang/rust-clippy/blob/eb4d88e690c431691bc0fd8eaa9f7096ecc2a723/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
| -rw-r--r-- | tests/ui/try_err.fixed | 10 | ||||
| -rw-r--r-- | tests/ui/try_err.rs | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/tests/ui/try_err.fixed b/tests/ui/try_err.fixed index aae4f8ac47f..f149bfb7774 100644 --- a/tests/ui/try_err.fixed +++ b/tests/ui/try_err.fixed @@ -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(()) +} diff --git a/tests/ui/try_err.rs b/tests/ui/try_err.rs index 927eccf2d54..841ec6b5d5c 100644 --- a/tests/ui/try_err.rs +++ b/tests/ui/try_err.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs - +#![feature(try_blocks)] #![deny(clippy::try_err)] #