diff options
| author | bors <bors@rust-lang.org> | 2017-08-13 07:50:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-08-13 07:50:36 +0000 |
| commit | d4fbc7a4e781a211b19fa2154184b37d3d53d32b (patch) | |
| tree | e624fdf7e2cc67d9079ce6064231a89eb0c0aa1d | |
| parent | adbce60d6f131e5b3789f01417dedb05e4489898 (diff) | |
| parent | eeb748aa12a3bb7f6bbd1205385fa0a0adbef90c (diff) | |
| download | rust-d4fbc7a4e781a211b19fa2154184b37d3d53d32b.tar.gz rust-d4fbc7a4e781a211b19fa2154184b37d3d53d32b.zip | |
Auto merge of #43813 - pengowen123:unused_result, r=estebank
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
| -rw-r--r-- | src/librustc_lint/unused.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/issue-43806.rs | 33 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index ba17df4cdca..7773891b5d0 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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, }; diff --git a/src/test/ui/issue-43806.rs b/src/test/ui/issue-43806.rs new file mode 100644 index 00000000000..7757a503c7e --- /dev/null +++ b/src/test/ui/issue-43806.rs @@ -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() {} |
