Skip to content

Commit 0892a73

Browse files
committed
change usages of explicit_item_bounds to bound_explicit_item_bounds
1 parent a57fa08 commit 0892a73

File tree

13 files changed

+76
-50
lines changed

13 files changed

+76
-50
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,12 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
319319
selftys: vec![],
320320
};
321321
let prohibit_opaque = tcx
322-
.explicit_item_bounds(def_id)
323-
.iter()
324-
.try_for_each(|(predicate, _)| predicate.visit_with(&mut visitor));
322+
.bound_explicit_item_bounds(def_id.to_def_id())
323+
.transpose_iter()
324+
.try_for_each(|bound| {
325+
let predicate = bound.map_bound(|&(predicate, _)| predicate).subst_identity();
326+
predicate.visit_with(&mut visitor)
327+
});
325328

326329
if let Some(ty) = prohibit_opaque.break_value() {
327330
visitor.visit_item(&item);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
360360
tcx,
361361
param_env,
362362
item_def_id,
363-
tcx.explicit_item_bounds(item_def_id).to_vec(),
363+
tcx.bound_explicit_item_bounds(item_def_id.to_def_id())
364+
.transpose_iter()
365+
.map(|bound| bound.map_bound(|b| *b).subst_identity())
366+
.collect::<Vec<_>>(),
364367
&FxIndexSet::default(),
365368
gat_def_id.def_id,
366369
gat_generics,
@@ -1122,10 +1125,11 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
11221125
/// Assuming the defaults are used, check that all predicates (bounds on the
11231126
/// assoc type and where clauses on the trait) hold.
11241127
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocItem, span: Span) {
1125-
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
1128+
let bounds = wfcx.tcx().bound_explicit_item_bounds(item.def_id);
11261129

11271130
debug!("check_associated_type_bounds: bounds={:?}", bounds);
1128-
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1131+
let wf_obligations = bounds.transpose_iter().flat_map(|b| {
1132+
let (bound, bound_span) = b.map_bound(|b| *b).subst_identity();
11291133
let normalized_bound = wfcx.normalize(span, None, bound);
11301134
traits::wf::predicate_obligations(
11311135
wfcx.infcx,

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ pub(super) fn item_bounds(
130130
tcx: TyCtxt<'_>,
131131
def_id: DefId,
132132
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
133-
let bounds = tcx.mk_predicates_from_iter(util::elaborate(
134-
tcx,
135-
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
136-
));
137-
ty::EarlyBinder(bounds)
133+
tcx.bound_explicit_item_bounds(def_id).map_bound(|bounds| {
134+
tcx.mk_predicates_from_iter(util::elaborate(
135+
tcx,
136+
bounds.iter().map(|&(bound, _span)| bound),
137+
))
138+
})
138139
}

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ fn check_must_not_suspend_ty<'tcx>(
571571
// FIXME: support adding the attribute to TAITs
572572
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
573573
let mut has_emitted = false;
574-
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
574+
for bound in fcx.tcx.bound_explicit_item_bounds(def).transpose_iter() {
575+
let predicate = bound.map_bound(|&(predicate, _)| predicate).subst_identity();
575576
// We only look at the `DefId`, so it is safe to skip the binder here.
576577
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
577578
predicate.kind().skip_binder()

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
7474
// For every projection predicate in the opaque type's explicit bounds,
7575
// check that the type that we're assigning actually satisfies the bounds
7676
// of the associated type.
77-
for &(pred, pred_span) in cx.tcx.explicit_item_bounds(def_id) {
77+
for bound in cx.tcx.bound_explicit_item_bounds(def_id).transpose_iter() {
78+
let (pred, pred_span) = bound.map_bound(|b| *b).subst_identity();
79+
7880
// Liberate bound regions in the predicate since we
7981
// don't actually care about lifetimes in this check.
8082
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());

compiler/rustc_lint/src/unused.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,23 +254,29 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
254254
}
255255
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
256256
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
257-
elaborate(cx.tcx, cx.tcx.explicit_item_bounds(def).iter().cloned())
258-
// We only care about self bounds for the impl-trait
259-
.filter_only_self()
260-
.find_map(|(pred, _span)| {
261-
// We only look at the `DefId`, so it is safe to skip the binder here.
262-
if let ty::PredicateKind::Clause(ty::Clause::Trait(
263-
ref poly_trait_predicate,
264-
)) = pred.kind().skip_binder()
265-
{
266-
let def_id = poly_trait_predicate.trait_ref.def_id;
267-
268-
is_def_must_use(cx, def_id, span)
269-
} else {
270-
None
271-
}
272-
})
273-
.map(|inner| MustUsePath::Opaque(Box::new(inner)))
257+
elaborate(
258+
cx.tcx,
259+
cx.tcx
260+
.bound_explicit_item_bounds(def)
261+
.transpose_iter()
262+
.map(|bound| bound.map_bound(|b| *b).subst_identity()),
263+
)
264+
// We only care about self bounds for the impl-trait
265+
.filter_only_self()
266+
.find_map(|(pred, _span)| {
267+
// We only look at the `DefId`, so it is safe to skip the binder here.
268+
if let ty::PredicateKind::Clause(ty::Clause::Trait(
269+
ref poly_trait_predicate,
270+
)) = pred.kind().skip_binder()
271+
{
272+
let def_id = poly_trait_predicate.trait_ref.def_id;
273+
274+
is_def_must_use(cx, def_id, span)
275+
} else {
276+
None
277+
}
278+
})
279+
.map(|inner| MustUsePath::Opaque(Box::new(inner)))
274280
}
275281
ty::Dynamic(binders, _, _) => binders.iter().find_map(|predicate| {
276282
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder()

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ impl<'tcx> TyCtxt<'tcx> {
16111611
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false };
16121612
let future_trait = self.require_lang_item(LangItem::Future, None);
16131613

1614-
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
1614+
self.bound_explicit_item_bounds(*def_id).skip_binder().iter().any(|(predicate, _)| {
16151615
let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() else {
16161616
return false;
16171617
};

compiler/rustc_mir_transform/src/generator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,9 @@ fn check_must_not_suspend_ty<'tcx>(
18001800
// FIXME: support adding the attribute to TAITs
18011801
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
18021802
let mut has_emitted = false;
1803-
for &(predicate, _) in tcx.explicit_item_bounds(def) {
1803+
for bound in tcx.bound_explicit_item_bounds(def).transpose_iter() {
1804+
let predicate = bound.map_bound(|&(pred, _)| pred).subst_identity();
1805+
18041806
// We only look at the `DefId`, so it is safe to skip the binder here.
18051807
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
18061808
predicate.kind().skip_binder()

compiler/rustc_privacy/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ where
269269
// and are visited by shallow visitors.
270270
self.visit_predicates(ty::GenericPredicates {
271271
parent: None,
272-
predicates: tcx.explicit_item_bounds(def_id),
272+
predicates: tcx.bound_explicit_item_bounds(def_id).skip_binder(),
273273
})?;
274274
}
275275
}
@@ -1784,7 +1784,10 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17841784
fn bounds(&mut self) -> &mut Self {
17851785
self.visit_predicates(ty::GenericPredicates {
17861786
parent: None,
1787-
predicates: self.tcx.explicit_item_bounds(self.item_def_id),
1787+
predicates: self
1788+
.tcx
1789+
.bound_explicit_item_bounds(self.item_def_id.to_def_id())
1790+
.skip_binder(),
17881791
});
17891792
self
17901793
}

compiler/rustc_trait_selection/src/traits/object_safety.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@ fn bounds_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span
297297
tcx.associated_items(trait_def_id)
298298
.in_definition_order()
299299
.filter(|item| item.kind == ty::AssocKind::Type)
300-
.flat_map(|item| tcx.explicit_item_bounds(item.def_id))
301-
.filter_map(|pred_span| predicate_references_self(tcx, *pred_span))
300+
.flat_map(|item| tcx.bound_explicit_item_bounds(item.def_id).transpose_iter())
301+
.map(|bound| bound.map_bound(|b| *b).subst_identity())
302+
.filter_map(|pred_span| predicate_references_self(tcx, pred_span))
302303
.collect()
303304
}
304305

0 commit comments

Comments
 (0)