Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 297b222

Browse files
authored
Rollup merge of rust-lang#110556 - kylematsuda:earlybinder-explicit-item-bounds, r=compiler-errors
Switch to `EarlyBinder` for `explicit_item_bounds` Part of the work to finish rust-lang#105779. This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`. r? `@compiler-errors` (hope it's okay to request you, since you reviewed rust-lang#110299 and rust-lang#110498 😃)
2 parents 666fee2 + 5a69b5d commit 297b222

File tree

28 files changed

+88
-71
lines changed

28 files changed

+88
-71
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
702702
.copied()
703703
.find_map(find_fn_kind_from_did),
704704
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => tcx
705-
.bound_explicit_item_bounds(def_id)
705+
.explicit_item_bounds(def_id)
706706
.subst_iter_copied(tcx, substs)
707707
.find_map(find_fn_kind_from_did),
708708
ty::Closure(_, substs) => match substs.as_closure().kind() {

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
320320
};
321321
let prohibit_opaque = tcx
322322
.explicit_item_bounds(def_id)
323-
.iter()
323+
.subst_identity_iter_copied()
324324
.try_for_each(|(predicate, _)| predicate.visit_with(&mut visitor));
325325

326326
if let Some(ty) = prohibit_opaque.break_value() {

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
839839
});
840840
self.types.insert(proj.def_id, (infer_ty, proj.substs));
841841
// Recurse into bounds
842-
for (pred, pred_span) in self.interner().bound_explicit_item_bounds(proj.def_id).subst_iter_copied(self.interner(), proj.substs) {
842+
for (pred, pred_span) in self.interner().explicit_item_bounds(proj.def_id).subst_iter_copied(self.interner(), proj.substs) {
843843
let pred = pred.fold_with(self);
844844
let pred = self.ocx.normalize(
845845
&ObligationCause::misc(self.span, self.body_id),
@@ -2023,7 +2023,7 @@ pub(super) fn check_type_bounds<'tcx>(
20232023
};
20242024

20252025
let obligations: Vec<_> = tcx
2026-
.bound_explicit_item_bounds(trait_ty.def_id)
2026+
.explicit_item_bounds(trait_ty.def_id)
20272027
.subst_iter_copied(tcx, rebased_substs)
20282028
.map(|(concrete_ty_bound, span)| {
20292029
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ 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.explicit_item_bounds(item_def_id)
364+
.subst_identity_iter_copied()
365+
.collect::<Vec<_>>(),
364366
&FxIndexSet::default(),
365367
gat_def_id.def_id,
366368
gat_generics,
@@ -1125,7 +1127,7 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
11251127
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
11261128

11271129
debug!("check_associated_type_bounds: bounds={:?}", bounds);
1128-
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1130+
let wf_obligations = bounds.subst_identity_iter_copied().flat_map(|(bound, bound_span)| {
11291131
let normalized_bound = wfcx.normalize(span, None, bound);
11301132
traits::wf::predicate_obligations(
11311133
wfcx.infcx,
@@ -1588,7 +1590,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
15881590
}
15891591
});
15901592
for (bound, bound_span) in tcx
1591-
.bound_explicit_item_bounds(opaque_ty.def_id)
1593+
.explicit_item_bounds(opaque_ty.def_id)
15921594
.subst_iter_copied(tcx, opaque_ty.substs)
15931595
{
15941596
let bound = self.wfcx.normalize(bound_span, None, bound);

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ fn opaque_type_bounds<'tcx>(
7979
pub(super) fn explicit_item_bounds(
8080
tcx: TyCtxt<'_>,
8181
def_id: LocalDefId,
82-
) -> &'_ [(ty::Predicate<'_>, Span)] {
82+
) -> ty::EarlyBinder<&'_ [(ty::Predicate<'_>, Span)]> {
8383
match tcx.opt_rpitit_info(def_id.to_def_id()) {
8484
// RPITIT's bounds are the same as opaque type bounds, but with
8585
// a projection self type.
8686
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
8787
let item = tcx.hir().get_by_def_id(opaque_def_id.expect_local()).expect_item();
8888
let opaque_ty = item.expect_opaque_ty();
89-
return opaque_type_bounds(
89+
return ty::EarlyBinder(opaque_type_bounds(
9090
tcx,
9191
opaque_def_id.expect_local(),
9292
opaque_ty.bounds,
@@ -95,15 +95,15 @@ pub(super) fn explicit_item_bounds(
9595
ty::InternalSubsts::identity_for_item(tcx, def_id),
9696
),
9797
item.span,
98-
);
98+
));
9999
}
100100
// These should have been fed!
101101
Some(ty::ImplTraitInTraitData::Impl { .. }) => unreachable!(),
102102
None => {}
103103
}
104104

105105
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
106-
match tcx.hir().get(hir_id) {
106+
let bounds = match tcx.hir().get(hir_id) {
107107
hir::Node::TraitItem(hir::TraitItem {
108108
kind: hir::TraitItemKind::Type(bounds, _),
109109
span,
@@ -123,16 +123,18 @@ pub(super) fn explicit_item_bounds(
123123
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
124124
}
125125
_ => bug!("item_bounds called on {:?}", def_id),
126-
}
126+
};
127+
ty::EarlyBinder(bounds)
127128
}
128129

129130
pub(super) fn item_bounds(
130131
tcx: TyCtxt<'_>,
131132
def_id: DefId,
132133
) -> 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)
134+
tcx.explicit_item_bounds(def_id).map_bound(|bounds| {
135+
tcx.mk_predicates_from_iter(util::elaborate(
136+
tcx,
137+
bounds.iter().map(|&(bound, _span)| bound),
138+
))
139+
})
138140
}

compiler/rustc_hir_analysis/src/variance/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
153153
let mut collector =
154154
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
155155
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id);
156-
for pred in tcx.bound_explicit_item_bounds(item_def_id.to_def_id()).transpose_iter() {
157-
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
156+
for (pred, _) in tcx.explicit_item_bounds(item_def_id).subst_iter_copied(tcx, id_substs) {
158157
debug!(?pred);
159158

160159
// We only ignore opaque type substs if the opaque type is the outermost type.

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
530530
for ty in [first_ty, second_ty] {
531531
for (pred, _) in self
532532
.tcx
533-
.bound_explicit_item_bounds(rpit_def_id)
533+
.explicit_item_bounds(rpit_def_id)
534534
.subst_iter_copied(self.tcx, substs)
535535
{
536536
let pred = pred.kind().rebind(match pred.kind().skip_binder() {

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
172172
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
173173
.deduce_closure_signature_from_predicates(
174174
expected_ty,
175-
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
175+
self.tcx.explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
176176
),
177177
ty::Dynamic(ref object_type, ..) => {
178178
let sig = object_type.projection_bounds().find_map(|pb| {
@@ -713,13 +713,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
713713
}
714714
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
715715
.tcx
716-
.bound_explicit_item_bounds(def_id)
716+
.explicit_item_bounds(def_id)
717717
.subst_iter_copied(self.tcx, substs)
718718
.find_map(|(p, s)| get_future_output(p, s))?,
719719
ty::Error(_) => return None,
720720
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => self
721721
.tcx
722-
.bound_explicit_item_bounds(proj.def_id)
722+
.explicit_item_bounds(proj.def_id)
723723
.subst_iter_copied(self.tcx, proj.substs)
724724
.find_map(|(p, s)| get_future_output(p, s))?,
725725
_ => span_bug!(

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ 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 &(predicate, _) in fcx.tcx.explicit_item_bounds(def).skip_binder() {
575575
// We only look at the `DefId`, so it is safe to skip the binder here.
576576
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
577577
predicate.kind().skip_binder()

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl<'tcx> InferCtxt<'tcx> {
402402
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
403403
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
404404

405-
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs).find_map(
405+
self.tcx.explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs).find_map(
406406
|(predicate, _)| {
407407
predicate
408408
.kind()

0 commit comments

Comments
 (0)