Skip to content

Commit f3b279f

Browse files
committed
add EarlyBinder to output of explicit_item_bounds; replace bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query
1 parent 0892a73 commit f3b279f

File tree

26 files changed

+49
-56
lines changed

26 files changed

+49
-56
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

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

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,8 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
318318
tcx,
319319
selftys: vec![],
320320
};
321-
let prohibit_opaque = tcx
322-
.bound_explicit_item_bounds(def_id.to_def_id())
323-
.transpose_iter()
324-
.try_for_each(|bound| {
321+
let prohibit_opaque =
322+
tcx.explicit_item_bounds(def_id).transpose_iter().try_for_each(|bound| {
325323
let predicate = bound.map_bound(|&(predicate, _)| predicate).subst_identity();
326324
predicate.visit_with(&mut visitor)
327325
});

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
360360
tcx,
361361
param_env,
362362
item_def_id,
363-
tcx.bound_explicit_item_bounds(item_def_id.to_def_id())
363+
tcx.explicit_item_bounds(item_def_id)
364364
.transpose_iter()
365365
.map(|bound| bound.map_bound(|b| *b).subst_identity())
366366
.collect::<Vec<_>>(),
@@ -1125,7 +1125,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
11251125
/// Assuming the defaults are used, check that all predicates (bounds on the
11261126
/// assoc type and where clauses on the trait) hold.
11271127
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocItem, span: Span) {
1128-
let bounds = wfcx.tcx().bound_explicit_item_bounds(item.def_id);
1128+
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
11291129

11301130
debug!("check_associated_type_bounds: bounds={:?}", bounds);
11311131
let wf_obligations = bounds.transpose_iter().flat_map(|b| {
@@ -1592,7 +1592,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
15921592
}
15931593
});
15941594
for (bound, bound_span) in tcx
1595-
.bound_explicit_item_bounds(opaque_ty.def_id)
1595+
.explicit_item_bounds(opaque_ty.def_id)
15961596
.subst_iter_copied(tcx, opaque_ty.substs)
15971597
{
15981598
let bound = self.wfcx.normalize(bound_span, None, bound);

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 7 additions & 6 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,14 +123,15 @@ 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-
tcx.bound_explicit_item_bounds(def_id).map_bound(|bounds| {
134+
tcx.explicit_item_bounds(def_id).map_bound(|bounds| {
134135
tcx.mk_predicates_from_iter(util::elaborate(
135136
tcx,
136137
bounds.iter().map(|&(bound, _span)| bound),

compiler/rustc_hir_analysis/src/variance/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +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() {
156+
for pred in tcx.explicit_item_bounds(item_def_id).transpose_iter() {
157157
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
158158
debug!(?pred);
159159

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +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 bound in fcx.tcx.bound_explicit_item_bounds(def).transpose_iter() {
575-
let predicate = bound.map_bound(|&(predicate, _)| predicate).subst_identity();
574+
for bound in fcx.tcx.explicit_item_bounds(def).transpose_iter() {
575+
let predicate = bound.map_bound(|&(pred, _)| pred).subst_identity();
576576
// We only look at the `DefId`, so it is safe to skip the binder here.
577577
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
578578
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)