Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakis
Be explicit about using Binder::dummy This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders. Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet. r? ``@nikomatsakis``
This commit is contained in:
commit
ee2e97c416
34 changed files with 127 additions and 121 deletions
|
@ -135,7 +135,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
|||
let obligation = traits::Obligation::new(
|
||||
cause.clone(),
|
||||
self.param_env,
|
||||
trait_ref.without_const().to_predicate(tcx),
|
||||
ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
|
||||
);
|
||||
if !self.infcx.predicate_may_hold(&obligation) {
|
||||
debug!("overloaded_deref_ty: cannot match obligation");
|
||||
|
|
|
@ -120,7 +120,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
|
|||
cause: traits::ObligationCause::dummy(),
|
||||
param_env,
|
||||
recursion_depth: 0,
|
||||
predicate: trait_ref.without_const().to_predicate(self.tcx),
|
||||
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(self.tcx),
|
||||
};
|
||||
self.evaluate_obligation(&obligation).unwrap_or(traits::EvaluationResult::EvaluatedToErr)
|
||||
}
|
||||
|
|
|
@ -726,7 +726,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
let new_obligation = Obligation::new(
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
new_trait_ref.without_const().to_predicate(self.tcx),
|
||||
ty::Binder::dummy(new_trait_ref).without_const().to_predicate(self.tcx),
|
||||
);
|
||||
|
||||
if self.predicate_must_hold_modulo_regions(&new_obligation) {
|
||||
|
|
|
@ -418,7 +418,8 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||
| ty::PredicateKind::Coerce(_)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => {
|
||||
let pred = infcx.replace_bound_vars_with_placeholders(binder);
|
||||
let pred =
|
||||
ty::Binder::dummy(infcx.replace_bound_vars_with_placeholders(binder));
|
||||
ProcessResult::Changed(mk_pending(vec![
|
||||
obligation.with(pred.to_predicate(self.selcx.tcx())),
|
||||
]))
|
||||
|
|
|
@ -140,7 +140,8 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>(
|
|||
infcx.tcx.def_path_str(def_id)
|
||||
);
|
||||
|
||||
let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) };
|
||||
let trait_ref =
|
||||
ty::Binder::dummy(ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) });
|
||||
let obligation = Obligation {
|
||||
param_env,
|
||||
cause: ObligationCause::misc(span, hir::CRATE_HIR_ID),
|
||||
|
|
|
@ -250,7 +250,7 @@ fn predicates_reference_self(
|
|||
trait_def_id: DefId,
|
||||
supertraits_only: bool,
|
||||
) -> SmallVec<[Span; 1]> {
|
||||
let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_def_id));
|
||||
let trait_ref = ty::TraitRef::identity(tcx, trait_def_id);
|
||||
let predicates = if supertraits_only {
|
||||
tcx.super_predicates_of(trait_def_id)
|
||||
} else {
|
||||
|
@ -554,11 +554,11 @@ fn object_ty_for_trait<'tcx>(
|
|||
|
||||
let trait_ref = ty::TraitRef::identity(tcx, trait_def_id);
|
||||
|
||||
let trait_predicate = ty::Binder::dummy(ty::ExistentialPredicate::Trait(
|
||||
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref),
|
||||
));
|
||||
let trait_predicate = trait_ref.map_bound(|trait_ref| {
|
||||
ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref))
|
||||
});
|
||||
|
||||
let mut associated_types = traits::supertraits(tcx, ty::Binder::dummy(trait_ref))
|
||||
let mut associated_types = traits::supertraits(tcx, trait_ref)
|
||||
.flat_map(|super_trait_ref| {
|
||||
tcx.associated_items(super_trait_ref.def_id())
|
||||
.in_definition_order()
|
||||
|
@ -671,10 +671,10 @@ fn receiver_is_dispatchable<'tcx>(
|
|||
let param_env = tcx.param_env(method.def_id);
|
||||
|
||||
// Self: Unsize<U>
|
||||
let unsize_predicate = ty::TraitRef {
|
||||
let unsize_predicate = ty::Binder::dummy(ty::TraitRef {
|
||||
def_id: unsize_did,
|
||||
substs: tcx.mk_substs_trait(tcx.types.self_param, &[unsized_self_ty.into()]),
|
||||
}
|
||||
})
|
||||
.without_const()
|
||||
.to_predicate(tcx);
|
||||
|
||||
|
@ -689,7 +689,9 @@ fn receiver_is_dispatchable<'tcx>(
|
|||
}
|
||||
});
|
||||
|
||||
ty::TraitRef { def_id: unsize_did, substs }.without_const().to_predicate(tcx)
|
||||
ty::Binder::dummy(ty::TraitRef { def_id: unsize_did, substs })
|
||||
.without_const()
|
||||
.to_predicate(tcx)
|
||||
};
|
||||
|
||||
let caller_bounds: Vec<Predicate<'tcx>> = param_env
|
||||
|
@ -703,10 +705,10 @@ fn receiver_is_dispatchable<'tcx>(
|
|||
|
||||
// Receiver: DispatchFromDyn<Receiver[Self => U]>
|
||||
let obligation = {
|
||||
let predicate = ty::TraitRef {
|
||||
let predicate = ty::Binder::dummy(ty::TraitRef {
|
||||
def_id: dispatch_from_dyn_did,
|
||||
substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]),
|
||||
}
|
||||
})
|
||||
.without_const()
|
||||
.to_predicate(tcx);
|
||||
|
||||
|
@ -789,8 +791,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
|
|||
|
||||
// Compute supertraits of current trait lazily.
|
||||
if self.supertraits.is_none() {
|
||||
let trait_ref =
|
||||
ty::Binder::dummy(ty::TraitRef::identity(self.tcx, self.trait_def_id));
|
||||
let trait_ref = ty::TraitRef::identity(self.tcx, self.trait_def_id);
|
||||
self.supertraits = Some(
|
||||
traits::supertraits(self.tcx, trait_ref).map(|t| t.def_id()).collect(),
|
||||
);
|
||||
|
|
|
@ -27,7 +27,7 @@ use rustc_hir::lang_items::LangItem;
|
|||
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
|
||||
use rustc_middle::ty::subst::Subst;
|
||||
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, WithConstness};
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness};
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -1028,7 +1028,7 @@ fn normalize_to_error<'a, 'tcx>(
|
|||
cause: ObligationCause<'tcx>,
|
||||
depth: usize,
|
||||
) -> NormalizedTy<'tcx> {
|
||||
let trait_ref = projection_ty.trait_ref(selcx.tcx()).to_poly_trait_ref();
|
||||
let trait_ref = ty::Binder::dummy(projection_ty.trait_ref(selcx.tcx()));
|
||||
let trait_obligation = Obligation {
|
||||
cause,
|
||||
recursion_depth: depth,
|
||||
|
@ -1290,7 +1290,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
|||
|
||||
// If we are resolving `<T as TraitRef<...>>::Item == Type`,
|
||||
// start out by selecting the predicate `T as TraitRef<...>`:
|
||||
let poly_trait_ref = obligation.predicate.trait_ref(selcx.tcx()).to_poly_trait_ref();
|
||||
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
|
||||
let trait_obligation = obligation.with(poly_trait_ref.to_poly_trait_predicate());
|
||||
let _ = selcx.infcx().commit_if_ok(|_| {
|
||||
let impl_source = match selcx.select(&trait_obligation) {
|
||||
|
|
|
@ -141,6 +141,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
let placeholder_trait_predicate =
|
||||
self.infcx().replace_bound_vars_with_placeholders(trait_predicate);
|
||||
let placeholder_self_ty = placeholder_trait_predicate.self_ty();
|
||||
let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
|
||||
let (def_id, substs) = match *placeholder_self_ty.kind() {
|
||||
ty::Projection(proj) => (proj.item_def_id, proj.substs),
|
||||
ty::Opaque(def_id, substs) => (def_id, substs),
|
||||
|
@ -164,7 +165,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
obligations.extend(self.infcx.commit_if_ok(|_| {
|
||||
self.infcx
|
||||
.at(&obligation.cause, obligation.param_env)
|
||||
.sup(placeholder_trait_predicate.trait_ref.to_poly_trait_ref(), candidate.value)
|
||||
.sup(placeholder_trait_predicate.to_poly_trait_ref(), candidate.value)
|
||||
.map(|InferOk { obligations, .. }| obligations)
|
||||
.map_err(|_| Unimplemented)
|
||||
})?);
|
||||
|
@ -646,7 +647,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
obligations.push(Obligation::new(
|
||||
obligation.cause.clone(),
|
||||
obligation.param_env,
|
||||
ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)
|
||||
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind))
|
||||
.to_predicate(self.tcx()),
|
||||
));
|
||||
}
|
||||
|
@ -898,10 +899,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
);
|
||||
|
||||
// We can only make objects from sized types.
|
||||
let tr = ty::TraitRef::new(
|
||||
let tr = ty::Binder::dummy(ty::TraitRef::new(
|
||||
tcx.require_lang_item(LangItem::Sized, None),
|
||||
tcx.mk_substs_trait(source, &[]),
|
||||
);
|
||||
));
|
||||
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
|
||||
|
||||
// If the type is `Foo + 'a`, ensure that the type
|
||||
|
|
|
@ -248,7 +248,7 @@ pub fn predicate_for_trait_ref<'tcx>(
|
|||
cause,
|
||||
param_env,
|
||||
recursion_depth,
|
||||
predicate: trait_ref.without_const().to_predicate(tcx),
|
||||
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -349,7 +349,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
new_cause,
|
||||
depth,
|
||||
param_env,
|
||||
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
|
||||
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(tcx),
|
||||
)
|
||||
}),
|
||||
);
|
||||
|
@ -399,7 +399,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
cause.clone(),
|
||||
depth,
|
||||
param_env,
|
||||
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
|
||||
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(tcx),
|
||||
)
|
||||
}),
|
||||
);
|
||||
|
@ -416,7 +416,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
cause,
|
||||
self.recursion_depth,
|
||||
self.param_env,
|
||||
trait_ref.without_const().to_predicate(self.infcx.tcx),
|
||||
ty::Binder::dummy(trait_ref).without_const().to_predicate(self.infcx.tcx),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -443,9 +443,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
let obligations = self.nominal_obligations(uv.def.did, substs);
|
||||
self.out.extend(obligations);
|
||||
|
||||
let predicate = ty::PredicateKind::ConstEvaluatable(
|
||||
let predicate = ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(
|
||||
ty::Unevaluated::new(uv.def, substs),
|
||||
)
|
||||
))
|
||||
.to_predicate(self.tcx());
|
||||
let cause = self.cause(traits::MiscObligation);
|
||||
self.out.push(traits::Obligation::with_depth(
|
||||
|
@ -469,8 +469,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
cause,
|
||||
self.recursion_depth,
|
||||
self.param_env,
|
||||
ty::PredicateKind::WellFormed(resolved_constant.into())
|
||||
.to_predicate(self.tcx()),
|
||||
ty::Binder::dummy(ty::PredicateKind::WellFormed(
|
||||
resolved_constant.into(),
|
||||
))
|
||||
.to_predicate(self.tcx()),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -556,8 +558,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
cause,
|
||||
depth,
|
||||
param_env,
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(rty, r))
|
||||
.to_predicate(self.tcx()),
|
||||
ty::Binder::dummy(ty::PredicateKind::TypeOutlives(
|
||||
ty::OutlivesPredicate(rty, r),
|
||||
))
|
||||
.to_predicate(self.tcx()),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -646,7 +650,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
cause.clone(),
|
||||
depth,
|
||||
param_env,
|
||||
ty::PredicateKind::ObjectSafe(did).to_predicate(tcx),
|
||||
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(did))
|
||||
.to_predicate(tcx),
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
@ -673,7 +678,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
cause,
|
||||
self.recursion_depth,
|
||||
param_env,
|
||||
ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()),
|
||||
ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into()))
|
||||
.to_predicate(self.tcx()),
|
||||
));
|
||||
} else {
|
||||
// Yes, resolved, proceed with the result.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue