Skip to content

Commit d4fbc7a

Browse files
committed
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
2 parents adbce60 + eeb748a commit d4fbc7a

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/librustc_lint/unused.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,15 @@ 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::TyAdt(def, _) => check_must_use(cx, def.did, s.span, ""),
149+
ty::TyTuple(ref tys, _) if tys.is_empty() => return,
150+
ty::TyNever => return,
151+
ty::TyAdt(def, _) => {
152+
if def.variants.is_empty() {
153+
return;
154+
} else {
155+
check_must_use(cx, def.did, s.span, "")
156+
}
157+
},
150158
_ => false,
151159
};
152160

src/test/ui/issue-43806.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
enum Void {}
16+
17+
fn foo() {}
18+
19+
fn bar() -> ! {
20+
loop {}
21+
}
22+
23+
fn baz() -> Void {
24+
loop {}
25+
}
26+
27+
fn qux() {
28+
foo();
29+
bar();
30+
baz();
31+
}
32+
33+
fn main() {}

0 commit comments

Comments
 (0)