Skip to content

Commit 0b2c9f0

Browse files
committed
Fix unused_result lint triggering when a function returns () or !
Add a test for this case
1 parent 38bdbb7 commit 0b2c9f0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/librustc_lint/unused.rs

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
146146

147147
let t = cx.tables.expr_ty(&expr);
148148
let ty_warned = match t.sty {
149+
ty::TyTuple(ref tys, _) if tys.is_empty() => return,
150+
ty::TyNever => return,
149151
ty::TyAdt(def, _) => check_must_use(cx, def.did, s.span, ""),
150152
_ => false,
151153
};

src/test/ui/issue-43806.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// run-pass
12+
13+
#![deny(unused_results)]
14+
15+
fn foo() {}
16+
17+
fn bar() -> ! {
18+
loop {}
19+
}
20+
21+
fn qux() {
22+
foo();
23+
bar();
24+
}
25+
26+
fn main() {}

0 commit comments

Comments
 (0)