Skip to content

Commit cc5ea04

Browse files
committed
un-regress behavior of unused_results lint for booleans
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.
1 parent e266888 commit cc5ea04

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/librustc_lint/unused.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
182182
}
183183

184184
if !(ty_warned || fn_warned) {
185-
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
185+
match t.sty {
186+
// Historically, booleans have not been considered unused
187+
// results. (See Issue #44119.)
188+
ty::TyBool => return,
189+
_ => {
190+
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
191+
}
192+
}
186193
}
187194

188195
fn check_must_use(cx: &LateContext, def_id: DefId, sp: Span, describe_path: &str) -> bool {

src/test/compile-fail/unused-result.rs

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ fn main() {
4242
foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
4343
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used: some message
4444

45+
// as an exceptional case, booleans are not considered unused
46+
foo::<bool>();
47+
4548
let _ = foo::<isize>();
4649
let _ = foo::<MustUse>();
4750
let _ = foo::<MustUseMsg>();

0 commit comments

Comments
 (0)