Use map_bound(_ref) instead of Binder::bind when possible
This commit is contained in:
parent
a78a62fc99
commit
dd5c9bf139
24 changed files with 173 additions and 143 deletions
|
@ -1095,9 +1095,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
obligation.predicate
|
||||
);
|
||||
|
||||
match obligation.predicate.skip_binders() {
|
||||
let bound_predicate = obligation.predicate.bound_atom(tcx);
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateAtom::Trait(pred, _) => {
|
||||
let pred = ty::Binder::bind(pred);
|
||||
let pred = bound_predicate.map_bound_ref(|_| pred);
|
||||
associated_types.entry(span).or_default().extend(
|
||||
tcx.associated_items(pred.def_id())
|
||||
.in_definition_order()
|
||||
|
@ -1106,7 +1107,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
);
|
||||
}
|
||||
ty::PredicateAtom::Projection(pred) => {
|
||||
let pred = ty::Binder::bind(pred);
|
||||
let pred = bound_predicate.map_bound_ref(|_| pred);
|
||||
// A `Self` within the original bound will be substituted with a
|
||||
// `trait_object_dummy_self`, so check for that.
|
||||
let references_self =
|
||||
|
|
|
@ -192,6 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
obligation.predicate
|
||||
);
|
||||
|
||||
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
|
||||
if let ty::PredicateAtom::Projection(proj_predicate) =
|
||||
obligation.predicate.skip_binders()
|
||||
{
|
||||
|
@ -199,7 +200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// the complete signature.
|
||||
self.deduce_sig_from_projection(
|
||||
Some(obligation.cause.span),
|
||||
ty::Binder::bind(proj_predicate),
|
||||
bound_predicate.map_bound_ref(|_| proj_predicate),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -583,7 +583,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
while !queue.is_empty() {
|
||||
let obligation = queue.remove(0);
|
||||
debug!("coerce_unsized resolve step: {:?}", obligation);
|
||||
let trait_pred = match obligation.predicate.skip_binders() {
|
||||
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
|
||||
let trait_pred = match bound_predicate.skip_binder() {
|
||||
ty::PredicateAtom::Trait(trait_pred, _)
|
||||
if traits.contains(&trait_pred.def_id()) =>
|
||||
{
|
||||
|
@ -594,7 +595,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
has_unsized_tuple_coercion = true;
|
||||
}
|
||||
}
|
||||
ty::Binder::bind(trait_pred)
|
||||
bound_predicate.map_bound_ref(|_| trait_pred)
|
||||
}
|
||||
_ => {
|
||||
coercion.obligations.push(obligation);
|
||||
|
|
|
@ -226,13 +226,15 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
|
|||
// could be extended easily also to the other `Predicate`.
|
||||
let predicate_matches_closure = |p: Predicate<'tcx>| {
|
||||
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
|
||||
let bound_predicate = predicate.bound_atom(tcx);
|
||||
let bound_p = p.bound_atom(tcx);
|
||||
match (predicate.skip_binders(), p.skip_binders()) {
|
||||
(ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => {
|
||||
relator.relate(ty::Binder::bind(a), ty::Binder::bind(b)).is_ok()
|
||||
}
|
||||
(ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => {
|
||||
relator.relate(ty::Binder::bind(a), ty::Binder::bind(b)).is_ok()
|
||||
}
|
||||
(ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => relator
|
||||
.relate(bound_predicate.map_bound_ref(|_| a), bound_p.map_bound_ref(|_| b))
|
||||
.is_ok(),
|
||||
(ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => relator
|
||||
.relate(bound_predicate.map_bound_ref(|_| a), bound_p.map_bound_ref(|_| b))
|
||||
.is_ok(),
|
||||
_ => predicate == p,
|
||||
}
|
||||
};
|
||||
|
|
|
@ -328,14 +328,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
|
||||
kw::Try => {
|
||||
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
|
||||
let try_fn_ty = ty::Binder::bind(tcx.mk_fn_sig(
|
||||
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
iter::once(mut_u8),
|
||||
tcx.mk_unit(),
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
Abi::Rust,
|
||||
));
|
||||
let catch_fn_ty = ty::Binder::bind(tcx.mk_fn_sig(
|
||||
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[mut_u8, mut_u8].iter().cloned(),
|
||||
tcx.mk_unit(),
|
||||
false,
|
||||
|
|
|
@ -796,29 +796,30 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
// FIXME: do we want to commit to this behavior for param bounds?
|
||||
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
|
||||
|
||||
let bounds =
|
||||
self.param_env.caller_bounds().iter().map(ty::Predicate::skip_binders).filter_map(
|
||||
|predicate| match predicate {
|
||||
ty::PredicateAtom::Trait(trait_predicate, _) => {
|
||||
match trait_predicate.trait_ref.self_ty().kind() {
|
||||
ty::Param(ref p) if *p == param_ty => {
|
||||
Some(ty::Binder::bind(trait_predicate.trait_ref))
|
||||
}
|
||||
_ => None,
|
||||
let tcx = self.tcx;
|
||||
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
|
||||
let bound_predicate = predicate.bound_atom(tcx);
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateAtom::Trait(trait_predicate, _) => {
|
||||
match trait_predicate.trait_ref.self_ty().kind() {
|
||||
ty::Param(ref p) if *p == param_ty => {
|
||||
Some(bound_predicate.map_bound_ref(|_| trait_predicate.trait_ref))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
ty::PredicateAtom::Subtype(..)
|
||||
| ty::PredicateAtom::Projection(..)
|
||||
| ty::PredicateAtom::RegionOutlives(..)
|
||||
| ty::PredicateAtom::WellFormed(..)
|
||||
| ty::PredicateAtom::ObjectSafe(..)
|
||||
| ty::PredicateAtom::ClosureKind(..)
|
||||
| ty::PredicateAtom::TypeOutlives(..)
|
||||
| ty::PredicateAtom::ConstEvaluatable(..)
|
||||
| ty::PredicateAtom::ConstEquate(..)
|
||||
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
|
||||
},
|
||||
);
|
||||
}
|
||||
ty::PredicateAtom::Subtype(..)
|
||||
| ty::PredicateAtom::Projection(..)
|
||||
| ty::PredicateAtom::RegionOutlives(..)
|
||||
| ty::PredicateAtom::WellFormed(..)
|
||||
| ty::PredicateAtom::ObjectSafe(..)
|
||||
| ty::PredicateAtom::ClosureKind(..)
|
||||
| ty::PredicateAtom::TypeOutlives(..)
|
||||
| ty::PredicateAtom::ConstEvaluatable(..)
|
||||
| ty::PredicateAtom::ConstEquate(..)
|
||||
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
|
||||
}
|
||||
});
|
||||
|
||||
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
|
||||
let trait_ref = this.erase_late_bound_regions(&poly_trait_ref);
|
||||
|
|
|
@ -637,9 +637,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
};
|
||||
let mut format_pred = |pred: ty::Predicate<'tcx>| {
|
||||
match pred.skip_binders() {
|
||||
let bound_predicate = pred.bound_atom(tcx);
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateAtom::Projection(pred) => {
|
||||
let pred = ty::Binder::bind(pred);
|
||||
let pred = bound_predicate.map_bound_ref(|_| pred);
|
||||
// `<Foo as Iterator>::Item = String`.
|
||||
let trait_ref =
|
||||
pred.skip_binder().projection_ty.trait_ref(self.tcx);
|
||||
|
@ -658,8 +659,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
Some((obligation, trait_ref.self_ty()))
|
||||
}
|
||||
ty::PredicateAtom::Trait(poly_trait_ref, _) => {
|
||||
let poly_trait_ref = ty::Binder::bind(poly_trait_ref);
|
||||
let p = poly_trait_ref.skip_binder().trait_ref;
|
||||
let p = poly_trait_ref.trait_ref;
|
||||
let self_ty = p.self_ty();
|
||||
let path = p.print_only_trait_path();
|
||||
let obligation = format!("{}: {}", self_ty, path);
|
||||
|
|
|
@ -850,7 +850,8 @@ fn bounds_from_generic_predicates<'tcx>(
|
|||
let mut projections = vec![];
|
||||
for (predicate, _) in predicates.predicates {
|
||||
debug!("predicate {:?}", predicate);
|
||||
match predicate.skip_binders() {
|
||||
let bound_predicate = predicate.bound_atom(tcx);
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateAtom::Trait(trait_predicate, _) => {
|
||||
let entry = types.entry(trait_predicate.self_ty()).or_default();
|
||||
let def_id = trait_predicate.def_id();
|
||||
|
@ -861,7 +862,7 @@ fn bounds_from_generic_predicates<'tcx>(
|
|||
}
|
||||
}
|
||||
ty::PredicateAtom::Projection(projection_pred) => {
|
||||
projections.push(ty::Binder::bind(projection_pred));
|
||||
projections.push(bound_predicate.map_bound_ref(|_| projection_pred));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -317,7 +317,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
|
|||
}
|
||||
}
|
||||
|
||||
let se_ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
|
||||
let se_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))].iter().cloned(),
|
||||
tcx.types.isize,
|
||||
false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue