Skip to content

Commit 213be32

Browse files
Filter out non-Self supertrait predicates in unused_must_use
1 parent af63e3b commit 213be32

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

compiler/rustc_lint/src/unused.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,18 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
251251
.map(|inner| MustUsePath::Boxed(Box::new(inner)))
252252
}
253253
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
254-
ty::Opaque(def, _) => {
254+
ty::Opaque(def, substs) => {
255255
elaborate_predicates_with_span(
256256
cx.tcx,
257-
cx.tcx.explicit_item_bounds(def).iter().cloned(),
257+
cx.tcx.bound_explicit_item_bounds(def).subst_iter_copied(cx.tcx, substs),
258258
)
259259
.filter_map(|obligation| {
260260
// We only look at the `DefId`, so it is safe to skip the binder here.
261-
if let ty::PredicateKind::Trait(ref poly_trait_predicate) =
261+
if let ty::PredicateKind::Trait(ref trait_predicate) =
262262
obligation.predicate.kind().skip_binder()
263+
&& trait_predicate.self_ty() == ty
263264
{
264-
let def_id = poly_trait_predicate.trait_ref.def_id;
265-
266-
is_def_must_use(cx, def_id, span)
265+
is_def_must_use(cx, trait_predicate.def_id(), span)
267266
} else {
268267
None
269268
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
3+
// Make sure that we only consider *Self* supertrait predicates
4+
// in the `unused_must_use` lint.
5+
6+
#![feature(trait_alias)]
7+
#![deny(unused_must_use)]
8+
9+
trait Foo<T> = Sized where T: Iterator;
10+
11+
fn test<T: Iterator>() -> impl Foo<T> {}
12+
13+
fn main() {
14+
test::<std::iter::Once<()>>();
15+
}

0 commit comments

Comments
 (0)