Skip to content

Commit 0347280

Browse files
committed
Auto merge of rust-lang#13107 - yaxum62:i5757, r=xFrednet
Add test for `try_err` lint within try blocks. Fixes rust-lang#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
2 parents 1ea827f + 1821def commit 0347280

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tests/ui/try_err.fixed

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@aux-build:proc_macros.rs
2-
2+
#![feature(try_blocks)]
33
#![deny(clippy::try_err)]
44
#![allow(
55
clippy::unnecessary_wraps,
@@ -152,3 +152,11 @@ pub fn try_return(x: bool) -> Result<i32, i32> {
152152
}
153153
Ok(0)
154154
}
155+
156+
// Test that the lint is suppressed in try block.
157+
pub fn try_block() -> Result<(), i32> {
158+
let _: Result<_, i32> = try {
159+
Err(1)?;
160+
};
161+
Ok(())
162+
}

tests/ui/try_err.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@aux-build:proc_macros.rs
2-
2+
#![feature(try_blocks)]
33
#![deny(clippy::try_err)]
44
#![allow(
55
clippy::unnecessary_wraps,
@@ -152,3 +152,11 @@ pub fn try_return(x: bool) -> Result<i32, i32> {
152152
}
153153
Ok(0)
154154
}
155+
156+
// Test that the lint is suppressed in try block.
157+
pub fn try_block() -> Result<(), i32> {
158+
let _: Result<_, i32> = try {
159+
Err(1)?;
160+
};
161+
Ok(())
162+
}

0 commit comments

Comments
 (0)