RS.CLIPPY.TRY_ERR
Return errors explicitly rather than hiding them behind a `?`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: try_err. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of Err(x)?.
Why restrict this?
The ? operator is designed to allow calls that
can fail to be easily chained. For example, foo()?.bar() or
foo(bar()?). Because Err(x)? can't be used that way (it will
always return), it is more clear to write return Err(x).
Example
fn foo(fail: bool) -> Result<i32, String> {
if fail {
Err("failed")?;
}
Ok(0)
}
Could be written:
fn foo(fail: bool) -> Result<i32, String> {
if fail {
return Err("failed".into());
}
Ok(0)
}