

invert check for `clippy::try_err` and disable it inside of try blocks · Issue #...
source link: https://github.com/rust-lang/rust-clippy/issues/5757
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Right now clippy lints instances of returning bare Err
's via ?
Err("foo")?; // clippy hates this return Err("foo".into()); // clippy's preference
This perhaps not the best default going forward. Here are the upcoming concerns that make me prefer using Err("")?
.
Try Blocks
Once try blocks are stabilized return Err
and Err?
will start to mean two different things. A bare return will return to the function scope, where as ?
returns are scoped to the innermost try block. To resolve this we should just not apply this lint to expressions inside of try blocks.
Error Return Traces and Try Trait interop
In future rust may have error return traces added to the Try trait where each ?
location passes a location to the inner error type to store so it can build up its own lightweight no_std compatible backtrace type that doesn't include any irrelevant frames. These frames would most likely be passed in by the implementation of the Try
trait for Result
. By returning via return Err("".into());
instead of ?
we avoid this codepath and prevent the error return traces from being populated.
In order to ensure the best compatibility with current and future version of the Try
trait we should prefer utilizing the core error propagation logic when propagating errors rather than recreating a low budget version of that logic manually.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK