Skip to content

Commit

Permalink
Auto merge of #43813 - pengowen123:unused_result, r=estebank
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Aug 13, 2017
2 parents adbce60 + eeb748a commit d4fbc7a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {

let t = cx.tables.expr_ty(&expr);
let ty_warned = match t.sty {
ty::TyAdt(def, _) => check_must_use(cx, def.did, s.span, ""),
ty::TyTuple(ref tys, _) if tys.is_empty() => return,
ty::TyNever => return,
ty::TyAdt(def, _) => {
if def.variants.is_empty() {
return;
} else {
check_must_use(cx, def.did, s.span, "")
}
},
_ => false,
};

Expand Down
33 changes: 33 additions & 0 deletions src/test/ui/issue-43806.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-pass

#![deny(unused_results)]

enum Void {}

fn foo() {}

fn bar() -> ! {
loop {}
}

fn baz() -> Void {
loop {}
}

fn qux() {
foo();
bar();
baz();
}

fn main() {}

0 comments on commit d4fbc7a

Please sign in to comment.