Skip to content
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

Merged
merged 2 commits into from
Aug 13, 2017

Conversation

pengowen123
Copy link
Contributor

@pengowen123 pengowen123 commented Aug 11, 2017

Also added a test to prevent this from happening again.

Fixes #43806

@rust-highfive
Copy link
Collaborator

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.

@estebank
Copy link
Contributor

r=me when the tests pass

@@ -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,
Copy link
Member

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?)

Copy link
Contributor Author

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.

@pengowen123
Copy link
Contributor Author

I implemented @scottmcm's suggestion, so empty enums are treated the same as !.

@pengowen123 pengowen123 changed the title Fix unused_result lint triggering when a function returns () or ! Fix unused_result lint triggering when a function returns (), ! or an empty enum Aug 12, 2017
@alexcrichton
Copy link
Member

@bors: r=estebank

@bors
Copy link
Contributor

bors commented Aug 12, 2017

📌 Commit eeb748a has been approved by estebank

@alexcrichton alexcrichton added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 12, 2017
@bors
Copy link
Contributor

bors commented Aug 13, 2017

⌛ Testing commit eeb748a with merge d4fbc7a...

bors added a commit that referenced this pull request Aug 13, 2017
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
@bors
Copy link
Contributor

bors commented Aug 13, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: estebank
Pushing d4fbc7a to master...

@bors bors merged commit eeb748a into rust-lang:master Aug 13, 2017
zackmdavis added a commit to zackmdavis/rust that referenced this pull request Aug 28, 2017
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants