Skip to content

Add ignored_result_err lint to detect discarded Result error variants - #17326

Open
scuzzycheese wants to merge 1 commit into
rust-lang:masterfrom
scuzzycheese:ignored_result_err
Open

scuzzycheese wants to merge 1 commit into
rust-lang:masterfrom
scuzzycheese:ignored_result_err

Conversation

@scuzzycheese

@scuzzycheese scuzzycheese commented Jun 30, 2026 •

Copy link
Copy Markdown

View all comments

changelog: new lint: [ignored_result_err]: Add ignored_result_err lint to detect discarded Result error variants. fixes #16107

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 30, 2026
@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@github-actions

github-actions Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Lintcheck changes for 95c0e72

Lint Added Removed Changed
clippy::ignored_result_err 309 0 0

This comment will be updated if you push new changes

@dswij

dswij commented Jul 2, 2026

Copy link
Copy Markdown
Member

r? clippy

@rustbot rustbot assigned flip1995 and unassigned dswij Jul 2, 2026
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jul 6, 2026
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jul 6, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 6, 2026
@scuzzycheese

Copy link
Copy Markdown
Author

Re-opening PR, I made mistake by resetting my origin.

@scuzzycheese scuzzycheese reopened this Jul 6, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 6, 2026
@scuzzycheese

Copy link
Copy Markdown
Author

@rustbot ready

@scuzzycheese

Copy link
Copy Markdown
Author

Hi @flip1995
Just bumping this since I accidentally closed and reopened it a few days ago, which threw off the bot status.
Whenever you have some free time, I’d love to get your feedback on the implementation!

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@scuzzycheese

Copy link
Copy Markdown
Author

@rustbot ready

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@scuzzycheese

Copy link
Copy Markdown
Author

@flip1995 - Any movement on this?

@scuzzycheese

Copy link
Copy Markdown
Author

@flip1995 - ping! :D

@scuzzycheese

Copy link
Copy Markdown
Author

@flip1995 - Just a follow up on this.

@scuzzycheese

Copy link
Copy Markdown
Author

@flip1995 - ping

@CommanderStorm

Copy link
Copy Markdown
Contributor

r? clippy

@rustbot rustbot assigned Manishearth and unassigned flip1995 Sep 11, 2026
@Manishearth

Copy link
Copy Markdown
Member

I don't think I'll have time to look at this either

r? @Clippy

I'm a bit busy with Rust security things right now

@rustbot rustbot assigned blyxyas and unassigned Manishearth Sep 15, 2026
@blyxyas

blyxyas commented Sep 16, 2026

Copy link
Copy Markdown
Member

Hello @scuzzycheese! Thanks for the contribution, being that you've been on this little 🏓 ping pong of reviewers (sometimes happens :/), I'll try to prioritize you. ❤️

@blyxyas

blyxyas commented Sep 16, 2026

Copy link
Copy Markdown
Member

Hmm, it seems that this lint is very similar to match_wild_err_arm what do you think about implementing some ideas of this lint into that other one? For one, I like the idea of relaxing the requirements for that lint to lint other "wildcard in Err arms" (such as an if let Ok(x) = y { .. } else { .. }), and for it to not require panics to lint.

What do you think about this idea?

@scuzzycheese

Copy link
Copy Markdown
Author

I have to say, that i'm not convinced that match_wild_err_arm is similar in many ways.

The purpose of this lint is to detect when the error variable is being discarded, which is what happens when there is no match being used.

It actually doesn't try to detect match arms at all. Here are the patterns it detects:

  • if let Ok(x) = expr (with or without else)
  • while let Ok(x) = expr
  • let Ok(x) = expr else { ... }

I feel like match_wild_err_arm is a different use case, designed to catch a different thing. Can if I can't incorporate the above expressions into match_wild_err_arm, then it's not a particularly useful lint.

I honestly feel like these are two different use cases. And they should be able to be used independently.

@blyxyas

blyxyas commented Sep 28, 2026

Copy link
Copy Markdown
Member

The bad pattern here is discarding the error form, right? Good code does not discard errors, it handles them. So in the case of this lint, we're encountering an unhandled error.

In the case of match_wild_err_arm, it's also about unhandled errors. The only difference is that one has explicit behavior for the Error case and the other is effectively Err(_) => {}.

Even in this example: let Ok(x) = expr else { ... }, we are seeing the same behavior as

match expr {
    Ok(x) => x,
     Err(_) => {...}
}

@rustbot

This comment has been minimized.

@scuzzycheese

Copy link
Copy Markdown
Author

Ok, so are we saying we would take ALL the functionality into match_wild_err_arm? Because the whole reason I wrote this was to make sure that it captured the situations I think are dangerous.

@blyxyas

blyxyas commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Indeed ❤️!

Because the whole reason I wrote this was to make sure that it captured the situations I think are dangerous.

I know, and I understand that it can feel like we're valuing your work less just because we see that this two functionalities should go together. But looking at both these two helpful lints, we just don't see enough difference in user experience to warrant having to learn the two names and having two different documentation pages.

You're very welcome to merge the logic from PR into match_wild_err_arm , and I'm sorry for the lost work.

@scuzzycheese

scuzzycheese commented Oct 13, 2026 via email •

Copy link
Copy Markdown
Author

@rustbot

rustbot commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

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.

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.
@scuzzycheese
scuzzycheese force-pushed the ignored_result_err branch 3 times, most recently from 7fefdce to 95c0e72 Compare October 13, 2026 14:39
@scuzzycheese

scuzzycheese commented Oct 13, 2026 •

Copy link
Copy Markdown
Author

I have a.... query about putting this inside match_wild_err_arm.
match_wild_err_arm is included in pedantic. Whereas ignored_result_err was a restricted lint.
I found when moving this into match_wild_err_arm, the dogfood tests now failed with 25 new diagnostics across 25 new sites. This is... quite an impact. Which means, that if we just fold this into match_wild_err_arm, anyone who has pedantic turned on is highly likely to have to make code changes to make this pass, and it's could cause a lot of impact for many clippy users who have pedantic turned on.
I'm not sure this is the right course of action. If we leave it within ignored_result_err, it means these can be turned on specifically if a user wants it, whereas this is going to be forces on users if it's included in match_wild_err_arm.

Is this acceptable? I'm not convinced it's... a good choice.

What do you think?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lint-nominated Create an FCP-thread on Zulip for this PR needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A lint to check the ignoring of Err

7 participants