Skip to content

Commit 3d7677d

Browse files
authored
Rollup merge of #106970 - kylematsuda:earlybinder-item-bounds, r=lcnr
Switch to `EarlyBinder` for `item_bounds` query Part of the work to finish #105779 (also see rust-lang/types-team#78). Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `item_bounds` query and removes `bound_item_bounds`. r? `@lcnr`
2 parents 2808183 + f193eff commit 3d7677d

File tree

9 files changed

+16
-20
lines changed

9 files changed

+16
-20
lines changed

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ pub(super) fn explicit_item_bounds(
9999
}
100100
}
101101

102-
pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> &'_ ty::List<ty::Predicate<'_>> {
103-
tcx.mk_predicates(
102+
pub(super) fn item_bounds(
103+
tcx: TyCtxt<'_>,
104+
def_id: DefId,
105+
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
106+
let bounds = tcx.mk_predicates(
104107
util::elaborate_predicates(
105108
tcx,
106109
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
107110
)
108111
.map(|obligation| obligation.predicate),
109-
)
112+
);
113+
ty::EarlyBinder(bounds)
110114
}

compiler/rustc_infer/src/infer/outlives/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
298298
substs: SubstsRef<'tcx>,
299299
) -> impl Iterator<Item = ty::Region<'tcx>> {
300300
let tcx = self.tcx;
301-
let bounds = tcx.bound_item_bounds(def_id);
301+
let bounds = tcx.item_bounds(def_id);
302302
trace!("{:#?}", bounds.0);
303303
bounds
304304
.subst_iter(tcx, substs)

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ rustc_queries! {
272272
/// ```
273273
///
274274
/// Bounds from the parent (e.g. with nested impl trait) are not included.
275-
query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
275+
query item_bounds(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
276276
desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
277277
}
278278

compiler/rustc_middle/src/ty/util.rs

-7
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,6 @@ impl<'tcx> TyCtxt<'tcx> {
659659
ty::EarlyBinder(self.explicit_item_bounds(def_id))
660660
}
661661

662-
pub fn bound_item_bounds(
663-
self,
664-
def_id: DefId,
665-
) -> ty::EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
666-
ty::EarlyBinder(self.item_bounds(def_id))
667-
}
668-
669662
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
670663
ty::EarlyBinder(self.impl_subject(def_id))
671664
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11231123
Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..])))
11241124
}
11251125
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
1126-
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
1126+
self.tcx.item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
11271127
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
11281128
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
11291129
// args tuple will always be substs[1]

compiler/rustc_trait_selection/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
13751375
// Check whether the self-type is itself a projection.
13761376
// If so, extract what we know from the trait and try to come up with a good answer.
13771377
let bounds = match *obligation.predicate.self_ty().kind() {
1378-
ty::Alias(_, ref data) => tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs),
1378+
ty::Alias(_, ref data) => tcx.item_bounds(data.def_id).subst(tcx, data.substs),
13791379
ty::Infer(ty::TyVar(_)) => {
13801380
// If the self-type is an inference variable, then it MAY wind up
13811381
// being a projected type, so induce an ambiguity.

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
160160
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
161161
};
162162

163-
let candidate_predicate =
164-
tcx.bound_item_bounds(def_id).map_bound(|i| i[idx]).subst(tcx, substs);
163+
let candidate_predicate = tcx.item_bounds(def_id).map_bound(|i| i[idx]).subst(tcx, substs);
165164
let candidate = candidate_predicate
166165
.to_opt_poly_trait_pred()
167166
.expect("projection candidate is not a trait predicate")
@@ -510,7 +509,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
510509
// This maybe belongs in wf, but that can't (doesn't) handle
511510
// higher-ranked things.
512511
// Prevent, e.g., `dyn Iterator<Item = str>`.
513-
for bound in self.tcx().bound_item_bounds(assoc_type).transpose_iter() {
512+
for bound in self.tcx().item_bounds(assoc_type).transpose_iter() {
514513
let subst_bound =
515514
if defs.count() == 0 {
516515
bound.subst(tcx, trait_predicate.trait_ref.substs)

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16041604
);
16051605
}
16061606
};
1607-
let bounds = tcx.bound_item_bounds(def_id).subst(tcx, substs);
1607+
let bounds = tcx.item_bounds(def_id).subst(tcx, substs);
16081608

16091609
// The bounds returned by `item_bounds` may contain duplicates after
16101610
// normalization, so try to deduplicate when possible to avoid

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
647647
Some(ExprFnSig::Closure(decl, subs.as_closure().sig()))
648648
},
649649
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))),
650-
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
651-
sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id))
650+
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
651+
sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id).subst(cx.tcx, substs), cx.tcx.opt_parent(def_id))
652652
},
653653
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
654654
ty::Dynamic(bounds, _, _) => {

0 commit comments

Comments
 (0)