Add ignored_result_err lint to detect discarded Result error variants#17326
Add ignored_result_err lint to detect discarded Result error variants#17326scuzzycheese wants to merge 1 commit into
ignored_result_err lint to detect discarded Result error variants#17326Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @dswij (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for 714fead
This comment will be updated if you push new changes |
|
r? clippy |
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
Add a new restriction lint that warns when the Err variant of a Result
is implicitly discarded. The lint detects three patterns:
- `if let Ok(x) = expr` (with or without else)
- `while let Ok(x) = expr`
- `let Ok(x) = expr else { ... }`
In all these cases, the error value is lost, preventing detailed logging
and making error recovery impossible. The lint suggests using `match`
with an explicit `Err(e)` binding instead.
This is an opt-in restriction lint, enabled with:
#![warn(clippy::ignored_result_err)]
A configuration option `allow-ignored-result-err-in-tests = true` can be
set in clippy.toml to suppress the lint in `#[test]` functions and
`#[cfg(test)]` modules.
Tested via the compile-test UI test harness with cases covering all three
patterns, a negative case for `match` with bound Err, and a ui-toml test
verifying the allow-in-tests configuration works correctly.
49263b1 to
714fead
Compare
714fead to
39df31c
Compare
|
Re-opening PR, I made mistake by resetting my origin. |
|
@rustbot ready |
|
Hi @flip1995 |
|
☔ The latest upstream changes (possibly #15000) made this pull request unmergeable. Please resolve the merge conflicts. |
changelog: new lint: [
ignored_result_err]: Addignored_result_errlint to detect discarded Result error variants. fixes #16107