Skip to content

Commit

Permalink
un-regress behavior of unused_results lint for booleans
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zackmdavis committed Aug 28, 2017
1 parent e266888 commit cc5ea04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
}

if !(ty_warned || fn_warned) {
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
match t.sty {
// Historically, booleans have not been considered unused
// results. (See Issue #44119.)
ty::TyBool => return,
_ => {
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
}
}
}

fn check_must_use(cx: &LateContext, def_id: DefId, sp: Span, describe_path: &str) -> bool {
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/unused-result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ fn main() {
foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used: some message

// as an exceptional case, booleans are not considered unused
foo::<bool>();

let _ = foo::<isize>();
let _ = foo::<MustUse>();
let _ = foo::<MustUseMsg>();
Expand Down

0 comments on commit cc5ea04

Please sign in to comment.