From cc5ea04e1f384d33d818a084b05ea46fba043150 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 27 Aug 2017 20:41:12 -0700 Subject: [PATCH] un-regress behavior of `unused_results` lint for booleans MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This, as #43813, is due to the author of #43728 (specifically, 3645b062) 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 #43813. If 3645b062 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 #44119. --- src/librustc_lint/unused.rs | 9 ++++++++- src/test/compile-fail/unused-result.rs | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index cbc4ebe90fd09..e8de6c36ba18d 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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 { diff --git a/src/test/compile-fail/unused-result.rs b/src/test/compile-fail/unused-result.rs index 0c6c7fc5a0d75..c0417e6e997ca 100644 --- a/src/test/compile-fail/unused-result.rs +++ b/src/test/compile-fail/unused-result.rs @@ -42,6 +42,9 @@ fn main() { foo::(); //~ ERROR: unused `MustUse` which must be used foo::(); //~ ERROR: unused `MustUseMsg` which must be used: some message + // as an exceptional case, booleans are not considered unused + foo::(); + let _ = foo::(); let _ = foo::(); let _ = foo::();