about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOwen Sanchez <pengowen816@gmail.com>2017-08-11 13:43:33 -0700
committerOwen Sanchez <pengowen816@gmail.com>2017-08-11 13:43:33 -0700
commit0b2c9f03efc248680a8e7eeedb6e5f8da5947774 (patch)
tree6ffc5896d0390d1e25087d1ef9f87beaedf48cd8
parent38bdbb7cf9bebcc4b6331644f52f9d6e52754782 (diff)
downloadrust-0b2c9f03efc248680a8e7eeedb6e5f8da5947774.tar.gz
rust-0b2c9f03efc248680a8e7eeedb6e5f8da5947774.zip
Fix unused_result lint triggering when a function returns `()` or `!`
Add a test for this case
-rw-r--r--src/librustc_lint/unused.rs2
-rw-r--r--src/test/ui/issue-43806.rs26
2 files changed, 28 insertions, 0 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs
index ba17df4cdca..e5b818cd5fb 100644
--- a/src/librustc_lint/unused.rs
+++ b/src/librustc_lint/unused.rs
@@ -146,6 +146,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
 
         let t = cx.tables.expr_ty(&expr);
         let ty_warned = match t.sty {
+            ty::TyTuple(ref tys, _) if tys.is_empty() => return,
+            ty::TyNever => return,
             ty::TyAdt(def, _) => 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..df7f756127c
--- /dev/null
+++ b/src/test/ui/issue-43806.rs
@@ -0,0 +1,26 @@
+// 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)]
+
+fn foo() {}
+
+fn bar() -> ! {
+    loop {}
+}
+
+fn qux() {
+    foo();
+    bar();
+}
+
+fn main() {}