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

src/librustdoc/clean/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ fn clean_projection<'tcx>(
421421
if cx.tcx.is_impl_trait_in_trait(ty.skip_binder().def_id) {
422422
let bounds = cx
423423
.tcx
424-
.explicit_item_bounds(ty.skip_binder().def_id)
425-
.iter()
426-
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, ty.skip_binder().substs))
424+
.bound_explicit_item_bounds(ty.skip_binder().def_id)
425+
.subst_iter_copied(cx.tcx, ty.skip_binder().substs)
426+
.map(|(pred, _)| pred)
427427
.collect::<Vec<_>>();
428428
return clean_middle_opaque_bounds(cx, bounds);
429429
}
@@ -1315,10 +1315,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13151315
}
13161316

13171317
if let ty::TraitContainer = assoc_item.container {
1318-
let bounds = tcx.explicit_item_bounds(assoc_item.def_id);
1318+
let bounds = tcx
1319+
.bound_explicit_item_bounds(assoc_item.def_id)
1320+
.transpose_iter()
1321+
.map(|bound| bound.map_bound(|b| *b).subst_identity());
13191322
let predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates;
13201323
let predicates =
1321-
tcx.arena.alloc_from_iter(bounds.into_iter().chain(predicates).copied());
1324+
tcx.arena.alloc_from_iter(bounds.chain(predicates.iter().copied()));
13221325
let mut generics = clean_ty_generics(
13231326
cx,
13241327
tcx.generics_of(assoc_item.def_id),
@@ -1844,9 +1847,9 @@ pub(crate) fn clean_middle_ty<'tcx>(
18441847
// by looking up the bounds associated with the def_id.
18451848
let bounds = cx
18461849
.tcx
1847-
.explicit_item_bounds(def_id)
1848-
.iter()
1849-
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, substs))
1850+
.bound_explicit_item_bounds(def_id)
1851+
.subst_iter_copied(cx.tcx, substs)
1852+
.map(|(bound, _)| bound)
18501853
.collect::<Vec<_>>();
18511854
clean_middle_opaque_bounds(cx, bounds)
18521855
}

src/tools/clippy/clippy_lints/src/future_not_send.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
44
use rustc_hir::{Body, FnDecl};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind};
7+
use rustc_middle::ty::{self, AliasTy, Clause, PredicateKind};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::def_id::LocalDefId;
1010
use rustc_span::{sym, Span};
@@ -64,10 +64,9 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
6464
}
6565
let ret_ty = return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(fn_def_id).expect_owner());
6666
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() {
67-
let preds = cx.tcx.explicit_item_bounds(def_id);
67+
let preds = cx.tcx.bound_explicit_item_bounds(def_id);
6868
let mut is_future = false;
69-
for &(p, _span) in preds {
70-
let p = EarlyBinder(p).subst(cx.tcx, substs);
69+
for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) {
7170
if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
7271
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
7372
is_future = true;

src/tools/clippy/clippy_utils/src/ty.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
9090
return false;
9191
}
9292

93-
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
93+
for bound in cx.tcx.bound_explicit_item_bounds(def_id).transpose_iter() {
94+
let (predicate, _span) = bound.map_bound(|b| *b).subst_identity();
9495
match predicate.kind().skip_binder() {
9596
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
9697
// and check substituions to find `U`.
@@ -267,7 +268,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
267268
},
268269
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
269270
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
270-
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
271+
for (predicate, _) in cx.tcx.bound_explicit_item_bounds(*def_id).skip_binder() {
271272
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
272273
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
273274
return true;

0 commit comments

Comments
 (0)