-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add drop_result
lint
#11891
Add drop_result
lint
#11891
Conversation
cd038a3
to
2538551
Compare
CI finally passed! \o/ |
As far as useful suggestions go, I'm in favor of suggesting |
What about a case like this:
Not sure how often something like this happens. Let's run Reports
|
I would argue that the first one in The others in |
Would it be accepted in |
I think the alternative to the above cases is
So maybe rather restriction/pedantic? WDYT? |
I'm fine with removing it too but pedantic sounds good as well. Updating to reflect that. |
2538551
to
631e7da
Compare
Moved the lint to the pedantic level. |
631e7da
to
80780d8
Compare
☔ The latest upstream changes (presumably #11597) made this pull request unmergeable. Please resolve the merge conflicts. |
What do you think about adding a |
As you prefer. If you want a suggestion I can add it. |
I can't remember what Rust version shipped this, but now we can just write |
Just Playgrounded a bit: I think the lint is way more complex than I initially thought. If you use |
Again if we're not sure about this lint, we can close this PR and the related issue. It's fine. :) |
Oh good point. I'd actually argue that the this code is still worth linting on: let s: Result<S, ()> = Ok(S);
drop(s); The problem there is the same with dropping a temporary result. In practice, the caller probably isn't explicitly spelling out the It does seem tricky to know what suggestion is best here, so maybe it's best not to include a suggestion. But overall the lint still seems reliably useful to me. |
Coming back to this after a long time: Catching the refactoring case is a strong argument for the lint. However Clippy can't know if a refactoring is happening, so we could only catch this by accepting FPs in other cases. But as alternatives to dropping a Result change semantics in subtle ways, I don't feel like we should lint this, without a good suggestion. And every suggestion we come up with might change semantics. So we would have to explain this in the lint documentation, but then users have to read that documentation and understand the subtleties. So the only option would be to put this lint into I would accept this lint as a restriction lint, but the subtle differences of the |
Let's close it, I don't think this is really worth it. I think the related issue should also be closed. |
Fixes #9876.
I don't think there is any useful suggestion we could give to the user for this lint so I didn't add one.
r? @flip1995
changelog: Add
drop_result
lint.