-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix unused_result lint triggering when a function returns ()
, !
or an empty enum
#43813
Conversation
Add a test for this case
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
r=me when the tests pass |
src/librustc_lint/unused.rs
Outdated
@@ -146,6 +146,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { | |||
|
|||
let t = cx.tables.expr_ty(&expr); | |||
let ty_warned = match t.sty { | |||
ty::TyTuple(ref tys, _) if tys.is_empty() => return, | |||
ty::TyNever => return, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also apply to enum Void {}
, and other such uninhabited types? (Possibly like #38069?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. I'll add that.
I implemented @scottmcm's suggestion, so empty enums are treated the same as |
()
or !
()
, !
or an empty enum
@bors: r=estebank |
📌 Commit eeb748a has been approved by |
Fix unused_result lint triggering when a function returns `()`, `!` or an empty enum Also added a test to prevent this from happening again. Fixes #43806
☀️ Test successful - status-appveyor, status-travis |
This, as rust-lang#43813, is due to the author of rust-lang#43728 (specifically, 3645b06) being a damnably contemptible fool. Before this entire fiasco, we would return early from the unusedness late lints pass if the type of the expression within the `hir::StmtSemi` was `!`, `()`, or a boolean: these types would never get to the point of being marked as unused results. That is, until the dunce who somehow (!?) came to be trusted with the plum responsibility of implementing RFC 1940 (`#[must_use]` for functions) went and fouled everything up, removing the early returns based on the (stupid) thought that there would be no harm in it, since we would need to continue to check these types being returned from must_use functions (which was true for the booleans, at least). But there was harm—harm that any quarter-way-competent programmer would have surely forseen! For after the new functional-must-use checks, there was nothing to stop the previously-returned-early types from falling through to be marked by the unused-results lint!—a monumentally idiotic error that has cost the project tens of precious developer- and reviewer-minutes dealing with the fallout here and in rust-lang#43813. If 3645b06 is representative of the standard of craftsmanship the rising generation of software engineers holds themselves to, I weep for the future of our technological civilization. Resolves rust-lang#44119.
Also added a test to prevent this from happening again.
Fixes #43806