Skip to content

Commit

Permalink
Rollup merge of rust-lang#44122 - zackmdavis:booleans_were_not_unused…
Browse files Browse the repository at this point in the history
…_results, r=eddyb

un-regress behavior of `unused_results` lint for booleans

Resolves rust-lang#44119.
  • Loading branch information
Ariel Ben-Yehuda authored Aug 29, 2017
2 parents f33803d + cc5ea04 commit ff75c01
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 ff75c01

Please sign in to comment.