Skip to content

Commit d8673bc

Browse files
committed
in which the unused-must-use lint adapts to the world of impl-Trait
Resolves rust-lang#51560.
1 parent 5205ae8 commit d8673bc

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/librustc_lint/unused.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
5858
}
5959

6060
let t = cx.tables.expr_ty(&expr);
61-
let ty_warned = match t.sty {
61+
62+
let checkee_ty = if let ty::TyAnon(def, _) = t.sty {
63+
// get concrete type of the `impl Trait` (Issue #51560)
64+
cx.tcx.type_of(def)
65+
} else {
66+
t
67+
};
68+
69+
let ty_warned = match checkee_ty.sty {
6270
ty::TyTuple(ref tys) if tys.is_empty() => return,
6371
ty::TyNever => return,
6472
ty::TyAdt(def, _) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2018 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+
#![allow(dead_code)]
12+
#![deny(unused_must_use)]
13+
14+
trait CompilerHackingToDistractFromHeartbreak {}
15+
16+
#[must_use]
17+
struct IGuessICanMakeNewFriends {
18+
somehow: bool
19+
}
20+
21+
impl CompilerHackingToDistractFromHeartbreak for IGuessICanMakeNewFriends {}
22+
23+
fn its_not_fair() -> impl CompilerHackingToDistractFromHeartbreak {
24+
IGuessICanMakeNewFriends { somehow: false }
25+
}
26+
27+
fn main() {
28+
its_not_fair();
29+
//~^ ERROR unused `IGuessICanMakeNewFriends` which must be used
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused `IGuessICanMakeNewFriends` which must be used
2+
--> $DIR/issue-51560-must-use-impl-trait.rs:28:5
3+
|
4+
LL | its_not_fair();
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/issue-51560-must-use-impl-trait.rs:12:9
9+
|
10+
LL | #![deny(unused_must_use)]
11+
| ^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)