Skip to content

Commit cb5520b

Browse files
committed
Recognise #[must_use] on traits, affecting impl Trait
1 parent b55717f commit cb5520b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustc_lint/unused.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
6666
} else {
6767
match t.sty {
6868
ty::Adt(def, _) => check_must_use(cx, def.did, s.span, ""),
69+
ty::Opaque(def, _) => {
70+
let mut must_use = false;
71+
for (predicate, _) in cx.tcx.predicates_of(def).predicates {
72+
if let ty::Predicate::Trait(ref poly_trait_predicate) = predicate {
73+
let trait_ref = poly_trait_predicate.skip_binder().trait_ref;
74+
if check_must_use(cx, trait_ref.def_id, s.span, "implementer of ") {
75+
must_use = true;
76+
break;
77+
}
78+
}
79+
}
80+
must_use
81+
}
6982
_ => false,
7083
}
71-
}
84+
};
7285

7386
let mut fn_warned = false;
7487
let mut op_warned = false;

0 commit comments

Comments
 (0)