fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
- let ty::Binder(ref inner) = *self;
- inner.hash_stable(hcx, hasher);
+ self.skip_binder().hash_stable(hcx, hasher);
}
}
Obligation::new(
cause.clone(),
param_env,
- ty::Predicate::RegionOutlives(ty::Binder(ty::OutlivesPredicate(r1, r2))),
+ ty::Predicate::RegionOutlives(
+ ty::Binder::dummy(ty::OutlivesPredicate(r1, r2))),
),
UnpackedKind::Type(t1) =>
Obligation::new(
cause.clone(),
param_env,
- ty::Predicate::TypeOutlives(ty::Binder(ty::OutlivesPredicate(t1, r2))),
+ ty::Predicate::TypeOutlives(
+ ty::Binder::dummy(ty::OutlivesPredicate(t1, r2))),
),
}
})) as Box<dyn Iterator<Item = _>>
/// Result from a generalization operation. This includes
/// not only the generalized type, but also a bool flag
-/// indicating whether further WF checks are needed.q
+/// indicating whether further WF checks are needed.
struct Generalization<'tcx> {
ty: Ty<'tcx>,
-> RelateResult<'tcx, ty::Binder<T>>
where T: Relate<'tcx>
{
- Ok(ty::Binder(self.relate(a.skip_binder(), b.skip_binder())?))
+ Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
}
fn relate_item_substs(&mut self,
};
if let (Some(def_id), Some(ret_ty)) = (def_id, ret_ty) {
- if exp_is_struct && exp_found.expected == ret_ty.0 {
+ if exp_is_struct && &exp_found.expected == ret_ty.skip_binder() {
let message = format!(
"did you mean `{}(/* fields */)`?",
self.tcx.item_path_str(def_id)
debug!("higher_ranked_sub: OK result={:?}", result);
- Ok(ty::Binder(result))
+ Ok(ty::Binder::bind(result))
});
}
b,
result1);
- Ok(ty::Binder(result1))
+ Ok(ty::Binder::bind(result1))
});
fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
b,
result1);
- Ok(ty::Binder(result1))
+ Ok(ty::Binder::bind(result1))
});
fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
self.fields.trace.cause.clone(),
self.fields.param_env,
ty::Predicate::Subtype(
- ty::Binder(ty::SubtypePredicate {
+ ty::Binder::dummy(ty::SubtypePredicate {
a_is_expected: self.a_is_expected,
a,
b,
&data.parent_trait_ref);
match self.get_parent_trait_ref(&data.parent_code) {
Some(t) => Some(t),
- None => Some(format!("{}", parent_trait_ref.0.self_ty())),
+ None => Some(format!("{}", parent_trait_ref.skip_binder().self_ty())),
}
}
_ => None,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'tcx>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>) {
- let ty::Binder(trait_ref) = trait_ref;
+ let trait_ref = trait_ref.skip_binder();
let span = obligation.cause.span;
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) {
::syntax::abi::Abi::Rust
)
};
- format!("{}", ty::Binder(sig))
+ format!("{}", ty::Binder::bind(sig))
}
let argument_is_closure = expected_ref.skip_binder().substs.type_at(0).is_closure();
}
ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref);
- let ty = parent_trait_ref.0.self_ty();
+ let ty = parent_trait_ref.skip_binder().self_ty();
err.note(&format!("required because it appears within the type `{}`", ty));
obligated_types.push(ty);
err.note(
&format!("required because of the requirements on the impl of `{}` for `{}`",
parent_trait_ref,
- parent_trait_ref.0.self_ty()));
+ parent_trait_ref.skip_binder().self_ty()));
let parent_predicate = parent_trait_ref.to_predicate();
self.note_obligation_cause_code(err,
&parent_predicate,
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code {
let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref);
for obligated_type in obligated_types {
- if obligated_type == &parent_trait_ref.0.self_ty() {
+ if obligated_type == &parent_trait_ref.skip_binder().self_ty() {
return true;
}
}
// the method may have some early-bound lifetimes, add
// regions for those
- let substs = Substs::for_item(tcx, def_id,
- |_, _| tcx.types.re_erased,
- |def, _| trait_ref.substs().type_for_def(def));
+ let substs = trait_ref.map_bound(|trait_ref| {
+ Substs::for_item(
+ tcx, def_id,
+ |_, _| tcx.types.re_erased,
+ |def, _| trait_ref.substs.type_for_def(def))
+ });
// the trait type may have higher-ranked lifetimes in it;
// so erase them if they appear, so that we get the type
// at some particular call site
let substs = tcx.normalize_erasing_late_bound_regions(
ty::ParamEnv::reveal_all(),
- &ty::Binder(substs),
+ &substs
);
// It's possible that the method relies on where clauses that
impl<'tcx> TraitObligation<'tcx> {
fn self_ty(&self) -> ty::Binder<Ty<'tcx>> {
- ty::Binder(self.predicate.skip_binder().self_ty())
+ self.predicate.map_bound(|p| p.self_ty())
}
}
trait_def_id: DefId,
supertraits_only: bool) -> bool
{
- let trait_ref = ty::Binder(ty::TraitRef {
+ let trait_ref = ty::Binder::dummy(ty::TraitRef {
def_id: trait_def_id,
substs: Substs::identity_for_item(self, trait_def_id)
});
.any(|predicate| {
match predicate {
ty::Predicate::Trait(ref trait_pred) if trait_pred.def_id() == sized_def_id => {
- trait_pred.0.self_ty().is_self()
+ trait_pred.skip_binder().self_ty().is_self()
}
ty::Predicate::Projection(..) |
ty::Predicate::Trait(..) |
// Compute supertraits of current trait lazily.
if supertraits.is_none() {
- let trait_ref = ty::Binder(ty::TraitRef {
+ let trait_ref = ty::Binder::bind(ty::TraitRef {
def_id: trait_def_id,
substs: Substs::identity_for_item(self, trait_def_id)
});
// direct equality here because all of these types
// are part of the formal parameter listing, and
// hence there should be no inference variables.
- let projection_trait_ref = ty::Binder(data.trait_ref(self));
+ let projection_trait_ref = ty::Binder::bind(data.trait_ref(self));
let is_supertrait_of_current_trait =
supertraits.as_ref().unwrap().contains(&projection_trait_ref);
let def_id = projection_ty.item_def_id;
let ty_var = selcx.infcx().next_ty_var(
TypeVariableOrigin::NormalizeProjectionType(tcx.def_span(def_id)));
- let projection = ty::Binder(ty::ProjectionPredicate {
+ let projection = ty::Binder::dummy(ty::ProjectionPredicate {
projection_ty,
ty: ty_var
});
predicate);
match predicate {
ty::Predicate::Projection(data) => {
- let same_def_id =
- data.0.projection_ty.item_def_id == obligation.predicate.item_def_id;
+ let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;
let is_match = same_def_id && infcx.probe(|_| {
let data_poly_trait_ref =
// item with the correct name
let env_predicates = env_predicates.filter_map(|p| match p {
ty::Predicate::Projection(data) =>
- if data.0.projection_ty.item_def_id == obligation.predicate.item_def_id {
+ if data.projection_def_id() == obligation.predicate.item_def_id {
Some(data)
} else {
None
let gen_def_id = tcx.lang_items().gen_trait().unwrap();
- // Note: we unwrap the binder here but re-create it below (1)
- let ty::Binder((trait_ref, yield_ty, return_ty)) =
+ let predicate =
tcx.generator_trait_ref_and_outputs(gen_def_id,
obligation.predicate.self_ty(),
- gen_sig);
-
- let name = tcx.associated_item(obligation.predicate.item_def_id).name;
- let ty = if name == Symbol::intern("Return") {
- return_ty
- } else if name == Symbol::intern("Yield") {
- yield_ty
- } else {
- bug!()
- };
+ gen_sig)
+ .map_bound(|(trait_ref, yield_ty, return_ty)| {
+ let name = tcx.associated_item(obligation.predicate.item_def_id).name;
+ let ty = if name == Symbol::intern("Return") {
+ return_ty
+ } else if name == Symbol::intern("Yield") {
+ yield_ty
+ } else {
+ bug!()
+ };
- let predicate = ty::Binder(ty::ProjectionPredicate { // (1) recreate binder here
- projection_ty: ty::ProjectionTy {
- substs: trait_ref.substs,
- item_def_id: obligation.predicate.item_def_id,
- },
- ty: ty
- });
+ ty::ProjectionPredicate {
+ projection_ty: ty::ProjectionTy {
+ substs: trait_ref.substs,
+ item_def_id: obligation.predicate.item_def_id,
+ },
+ ty: ty
+ }
+ });
confirm_param_env_candidate(selcx, obligation, predicate)
.with_addl_obligations(vtable.nested)
// the `Output` associated type is declared on `FnOnce`
let fn_once_def_id = tcx.lang_items().fn_once_trait().unwrap();
- // Note: we unwrap the binder here but re-create it below (1)
- let ty::Binder((trait_ref, ret_type)) =
+ let predicate =
tcx.closure_trait_ref_and_return_type(fn_once_def_id,
obligation.predicate.self_ty(),
fn_sig,
- flag);
-
- let predicate = ty::Binder(ty::ProjectionPredicate { // (1) recreate binder here
- projection_ty: ty::ProjectionTy::from_ref_and_name(
- tcx,
- trait_ref,
- Symbol::intern(FN_OUTPUT_NAME),
- ),
- ty: ret_type
- });
+ flag)
+ .map_bound(|(trait_ref, ret_type)| {
+ ty::ProjectionPredicate {
+ projection_ty: ty::ProjectionTy::from_ref_and_name(
+ tcx,
+ trait_ref,
+ Symbol::intern(FN_OUTPUT_NAME),
+ ),
+ ty: ret_type
+ }
+ });
confirm_param_env_candidate(selcx, obligation, predicate)
}
// This suffices to allow chains like `FnMut` implemented in
// terms of `Fn` etc, but we could probably make this more
// precise still.
- let unbound_input_types = stack.fresh_trait_ref.input_types().any(|ty| ty.is_fresh());
+ let unbound_input_types =
+ stack.fresh_trait_ref.skip_binder().input_types().any(|ty| ty.is_fresh());
// this check was an imperfect workaround for a bug n the old
// intercrate mode, it should be removed when that goes away.
if unbound_input_types &&
-> Option<SelectionResult<'tcx, SelectionCandidate<'tcx>>>
{
let tcx = self.tcx();
- let trait_ref = &cache_fresh_trait_pred.0.trait_ref;
+ let trait_ref = &cache_fresh_trait_pred.skip_binder().trait_ref;
if self.can_use_global_caches(param_env) {
let cache = tcx.selection_cache.hashmap.borrow();
if let Some(cached) = cache.get(&trait_ref) {
candidate: SelectionResult<'tcx, SelectionCandidate<'tcx>>)
{
let tcx = self.tcx();
- let trait_ref = cache_fresh_trait_pred.0.trait_ref;
+ let trait_ref = cache_fresh_trait_pred.skip_binder().trait_ref;
if self.can_use_global_caches(param_env) {
let mut cache = tcx.selection_cache.hashmap.borrow_mut();
if let Some(trait_ref) = tcx.lift_to_global(&trait_ref) {
let lang_items = self.tcx().lang_items();
if lang_items.copy_trait() == Some(def_id) {
debug!("obligation self ty is {:?}",
- obligation.predicate.0.self_ty());
+ obligation.predicate.skip_binder().self_ty());
// User-defined copy impls are permitted, but only for
// structs and enums.
// before we go into the whole skolemization thing, just
// quickly check if the self-type is a projection at all.
- match obligation.predicate.0.trait_ref.self_ty().sty {
+ match obligation.predicate.skip_binder().trait_ref.self_ty().sty {
ty::TyProjection(_) | ty::TyAnon(..) => {}
ty::TyInfer(ty::TyVar(_)) => {
span_bug!(obligation.cause.span,
{
assert!(!skol_trait_ref.has_escaping_regions());
if let Err(_) = self.infcx.at(&obligation.cause, obligation.param_env)
- .sup(ty::Binder(skol_trait_ref), trait_bound) {
+ .sup(ty::Binder::dummy(skol_trait_ref), trait_bound) {
return false;
}
candidates: &mut SelectionCandidateSet<'tcx>)
-> Result<(),SelectionError<'tcx>>
{
- let kind = match self.tcx().lang_items().fn_trait_kind(obligation.predicate.0.def_id()) {
+ let kind = match self.tcx().lang_items().fn_trait_kind(obligation.predicate.def_id()) {
Some(k) => k,
None => { return Ok(()); }
};
// provide an impl, but only for suitable `fn` pointers
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
- if let ty::Binder(ty::FnSig {
+ if let ty::FnSig {
unsafety: hir::Unsafety::Normal,
abi: Abi::Rust,
variadic: false,
..
- }) = self_ty.fn_sig(self.tcx()) {
+ } = self_ty.fn_sig(self.tcx()).skip_binder() {
candidates.vec.push(FnPointerCandidate);
}
}
self.tcx().for_each_relevant_impl(
obligation.predicate.def_id(),
- obligation.predicate.0.trait_ref.self_ty(),
+ obligation.predicate.skip_binder().trait_ref.self_ty(),
|impl_def_id| {
self.probe(|this, snapshot| { /* [1] */
match this.match_impl(impl_def_id, obligation, snapshot) {
ty::TyGeneratorWitness(..) | ty::TyArray(..) | ty::TyClosure(..) |
ty::TyNever | ty::TyError => {
// safe for everything
- Where(ty::Binder(Vec::new()))
+ Where(ty::Binder::dummy(Vec::new()))
}
ty::TyStr | ty::TySlice(_) | ty::TyDynamic(..) | ty::TyForeign(..) => Never,
ty::TyTuple(tys) => {
- Where(ty::Binder(tys.last().into_iter().cloned().collect()))
+ Where(ty::Binder::bind(tys.last().into_iter().cloned().collect()))
}
ty::TyAdt(def, substs) => {
let sized_crit = def.sized_constraint(self.tcx());
// (*) binder moved here
- Where(ty::Binder(
+ Where(ty::Binder::bind(
sized_crit.iter().map(|ty| ty.subst(self.tcx(), substs)).collect()
))
}
match self_ty.sty {
ty::TyInfer(ty::IntVar(_)) | ty::TyInfer(ty::FloatVar(_)) |
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyError => {
- Where(ty::Binder(Vec::new()))
+ Where(ty::Binder::dummy(Vec::new()))
}
ty::TyUint(_) | ty::TyInt(_) | ty::TyBool | ty::TyFloat(_) |
ty::TyArray(element_ty, _) => {
// (*) binder moved here
- Where(ty::Binder(vec![element_ty]))
+ Where(ty::Binder::bind(vec![element_ty]))
}
ty::TyTuple(tys) => {
// (*) binder moved here
- Where(ty::Binder(tys.to_vec()))
+ Where(ty::Binder::bind(tys.to_vec()))
}
ty::TyClosure(def_id, substs) => {
let is_copy_trait = Some(trait_id) == self.tcx().lang_items().copy_trait();
let is_clone_trait = Some(trait_id) == self.tcx().lang_items().clone_trait();
if is_copy_trait || is_clone_trait {
- Where(ty::Binder(substs.upvar_tys(def_id, self.tcx()).collect()))
+ Where(ty::Binder::bind(substs.upvar_tys(def_id, self.tcx()).collect()))
} else {
Never
}
// 3. Re-bind the regions back to `for<'a> &'a int : Copy`
types.skip_binder().into_iter().flat_map(|ty| { // binder moved -\
- let ty: ty::Binder<Ty<'tcx>> = ty::Binder(ty); // <----------/
+ let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/
self.in_snapshot(|this, snapshot| {
let (skol_ty, skol_map) =
/// 1. For each constituent type `Y` in `X`, `Y : Foo` holds
/// 2. For each where-clause `C` declared on `Foo`, `[Self => X] C` holds.
fn confirm_auto_impl_candidate(&mut self,
- obligation: &TraitObligation<'tcx>,
- trait_def_id: DefId)
- -> VtableAutoImplData<PredicateObligation<'tcx>>
+ obligation: &TraitObligation<'tcx>,
+ trait_def_id: DefId)
+ -> VtableAutoImplData<PredicateObligation<'tcx>>
{
debug!("confirm_auto_impl_candidate({:?}, {:?})",
obligation,
trait_def_id);
- // binder is moved below
- let self_ty = self.infcx.shallow_resolve(obligation.predicate.skip_binder().self_ty());
- let types = self.constituent_types_for_ty(self_ty);
- self.vtable_auto_impl(obligation, trait_def_id, ty::Binder(types))
+ let types = obligation.predicate.map_bound(|inner| {
+ let self_ty = self.infcx.shallow_resolve(inner.self_ty());
+ self.constituent_types_for_ty(self_ty)
+ });
+ self.vtable_auto_impl(obligation, trait_def_id, types)
}
/// See `confirm_auto_impl_candidate`
{
debug!("confirm_closure_candidate({:?})", obligation);
- let kind = match self.tcx().lang_items().fn_trait_kind(obligation.predicate.0.def_id()) {
+ let kind = match self.tcx().lang_items().fn_trait_kind(obligation.predicate.def_id()) {
Some(k) => k,
None => bug!("closure candidate for non-fn trait {:?}", obligation)
};
// Trait+Kx+'a -> Trait+Ky+'b (upcasts).
(&ty::TyDynamic(ref data_a, r_a), &ty::TyDynamic(ref data_b, r_b)) => {
// See assemble_candidates_for_unsizing for more info.
- // Binders reintroduced below in call to mk_existential_predicates.
- let principal = data_a.skip_binder().principal();
- let iter = principal.into_iter().map(ty::ExistentialPredicate::Trait)
- .chain(data_a.skip_binder().projection_bounds()
- .map(|x| ty::ExistentialPredicate::Projection(x)))
- .chain(data_b.auto_traits().map(ty::ExistentialPredicate::AutoTrait));
- let new_trait = tcx.mk_dynamic(
- ty::Binder(tcx.mk_existential_predicates(iter)), r_b);
+ let existential_predicates = data_a.map_bound(|data_a| {
+ let principal = data_a.principal();
+ let iter = principal.into_iter().map(ty::ExistentialPredicate::Trait)
+ .chain(data_a.projection_bounds()
+ .map(|x| ty::ExistentialPredicate::Projection(x)))
+ .chain(data_b.auto_traits().map(ty::ExistentialPredicate::AutoTrait));
+ tcx.mk_existential_predicates(iter)
+ });
+ let new_trait = tcx.mk_dynamic(existential_predicates, r_b);
let InferOk { obligations, .. } =
self.infcx.at(&obligation.cause, obligation.param_env)
.eq(target, new_trait)
nested.push(Obligation::with_depth(cause,
obligation.recursion_depth + 1,
obligation.param_env,
- ty::Binder(outlives).to_predicate()));
+ ty::Binder::bind(outlives).to_predicate()));
}
// T -> Trait.
// If the type is `Foo+'a`, ensures that the type
// being cast to `Foo+'a` outlives `'a`:
let outlives = ty::OutlivesPredicate(source, r);
- push(ty::Binder(outlives).to_predicate());
+ push(ty::Binder::dummy(outlives).to_predicate());
}
// [T; n] -> [T].
-> ty::PolyTraitRef<'tcx>
{
let closure_type = self.infcx.closure_sig(closure_def_id, substs);
- let ty::Binder((trait_ref, _)) =
- self.tcx().closure_trait_ref_and_return_type(obligation.predicate.def_id(),
- obligation.predicate.0.self_ty(), // (1)
- closure_type,
- util::TupleArgumentsFlag::No);
+
// (1) Feels icky to skip the binder here, but OTOH we know
// that the self-type is an unboxed closure type and hence is
// in fact unparameterized (or at least does not reference any
// regions bound in the obligation). Still probably some
// refactoring could make this nicer.
- ty::Binder(trait_ref)
+ self.tcx().closure_trait_ref_and_return_type(obligation.predicate.def_id(),
+ obligation.predicate
+ .skip_binder().self_ty(), // (1)
+ closure_type,
+ util::TupleArgumentsFlag::No)
+ .map_bound(|(trait_ref, _)| trait_ref)
}
fn generator_trait_ref_unnormalized(&mut self,
-> ty::PolyTraitRef<'tcx>
{
let gen_sig = substs.generator_poly_sig(closure_def_id, self.tcx());
- let ty::Binder((trait_ref, ..)) =
- self.tcx().generator_trait_ref_and_outputs(obligation.predicate.def_id(),
- obligation.predicate.0.self_ty(), // (1)
- gen_sig);
+
// (1) Feels icky to skip the binder here, but OTOH we know
// that the self-type is an generator type and hence is
// in fact unparameterized (or at least does not reference any
// regions bound in the obligation). Still probably some
// refactoring could make this nicer.
- ty::Binder(trait_ref)
+ self.tcx().generator_trait_ref_and_outputs(obligation.predicate.def_id(),
+ obligation.predicate
+ .skip_binder().self_ty(), // (1)
+ gen_sig)
+ .map_bound(|(trait_ref, ..)| trait_ref)
}
/// Returns the obligations that are implied by instantiating an
None
} else {
Some(ty::Predicate::RegionOutlives(
- ty::Binder(ty::OutlivesPredicate(r, r_min))))
+ ty::Binder::dummy(ty::OutlivesPredicate(r, r_min))))
},
Component::Param(p) => {
let ty = tcx.mk_param(p.idx, p.name);
Some(ty::Predicate::TypeOutlives(
- ty::Binder(ty::OutlivesPredicate(ty, r_min))))
+ ty::Binder::dummy(ty::OutlivesPredicate(ty, r_min))))
},
Component::UnresolvedInferenceVariable(_) => {
def_id: fn_trait_def_id,
substs: self.mk_substs_trait(self_ty, &[arguments_tuple]),
};
- ty::Binder((trait_ref, sig.skip_binder().output()))
+ ty::Binder::bind((trait_ref, sig.skip_binder().output()))
}
pub fn generator_trait_ref_and_outputs(self,
def_id: fn_trait_def_id,
substs: self.mk_substs_trait(self_ty, &[]),
};
- ty::Binder((trait_ref, sig.skip_binder().yield_ty, sig.skip_binder().return_ty))
+ ty::Binder::bind((trait_ref, sig.skip_binder().yield_ty, sig.skip_binder().return_ty))
}
pub fn impl_is_default(self, node_item_def_id: DefId) -> bool {
-> RelateResult<'tcx, ty::Binder<T>>
where T: Relate<'tcx>
{
- Ok(ty::Binder(self.relate(a.skip_binder(), b.skip_binder())?))
+ Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
}
}
}
}
});
- Binder(value)
+ Binder::bind(value)
}
/// Returns a set of all late-bound regions that are constrained
where T : TypeFoldable<'tcx>,
{
let mut counter = 0;
- Binder(self.replace_late_bound_regions(sig, |_| {
+ Binder::bind(self.replace_late_bound_regions(sig, |_| {
counter += 1;
self.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrAnon(counter)))
}).0)
def_id, trait_id, rcvr_substs);
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs);
- let vtbl = tcx.trans_fulfill_obligation((param_env, ty::Binder(trait_ref)));
+ let vtbl = tcx.trans_fulfill_obligation((param_env, ty::Binder::bind(trait_ref)));
// Now that we know which impl is being used, we can dispatch to
// the actual function:
// from the substitution and the value being substituted into, and
// this trick achieves that).
- let substs = &trait_ref.0.substs;
+ let substs = &trait_ref.skip_binder().substs;
match *self {
- Predicate::Trait(ty::Binder(ref data)) =>
- Predicate::Trait(ty::Binder(data.subst(tcx, substs))),
- Predicate::Subtype(ty::Binder(ref data)) =>
- Predicate::Subtype(ty::Binder(data.subst(tcx, substs))),
- Predicate::RegionOutlives(ty::Binder(ref data)) =>
- Predicate::RegionOutlives(ty::Binder(data.subst(tcx, substs))),
- Predicate::TypeOutlives(ty::Binder(ref data)) =>
- Predicate::TypeOutlives(ty::Binder(data.subst(tcx, substs))),
- Predicate::Projection(ty::Binder(ref data)) =>
- Predicate::Projection(ty::Binder(data.subst(tcx, substs))),
+ Predicate::Trait(ref binder) =>
+ Predicate::Trait(binder.map_bound(|data| data.subst(tcx, substs))),
+ Predicate::Subtype(ref binder) =>
+ Predicate::Subtype(binder.map_bound(|data| data.subst(tcx, substs))),
+ Predicate::RegionOutlives(ref binder) =>
+ Predicate::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs))),
+ Predicate::TypeOutlives(ref binder) =>
+ Predicate::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs))),
+ Predicate::Projection(ref binder) =>
+ Predicate::Projection(binder.map_bound(|data| data.subst(tcx, substs))),
Predicate::WellFormed(data) =>
Predicate::WellFormed(data.subst(tcx, substs)),
Predicate::ObjectSafe(trait_def_id) =>
impl<'tcx> PolyTraitPredicate<'tcx> {
pub fn def_id(&self) -> DefId {
// ok to skip binder since trait def-id does not care about regions
- self.0.def_id()
+ self.skip_binder().def_id()
}
}
// This is because here `self` has a `Binder` and so does our
// return value, so we are preserving the number of binding
// levels.
- ty::Binder(self.0.projection_ty.trait_ref(tcx))
+ self.map_bound(|predicate| predicate.projection_ty.trait_ref(tcx))
}
pub fn ty(&self) -> Binder<Ty<'tcx>> {
- Binder(self.skip_binder().ty) // preserves binding levels
+ self.map_bound(|predicate| predicate.ty)
+ }
+
+ /// The DefId of the TraitItem for the associated type.
+ ///
+ /// Note that this is not the DefId of the TraitRef containing this
+ /// associated type, which is in tcx.associated_item(projection_def_id()).container.
+ pub fn projection_def_id(&self) -> DefId {
+ // ok to skip binder since trait def-id does not care about regions
+ self.skip_binder().projection_ty.item_def_id
}
}
impl<'tcx> ToPolyTraitRef<'tcx> for TraitRef<'tcx> {
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx> {
- assert!(!self.has_escaping_regions());
- ty::Binder(self.clone())
+ ty::Binder::dummy(self.clone())
}
}
impl<'tcx> ToPredicate<'tcx> for TraitRef<'tcx> {
fn to_predicate(&self) -> Predicate<'tcx> {
- // we're about to add a binder, so let's check that we don't
- // accidentally capture anything, or else that might be some
- // weird debruijn accounting.
- assert!(!self.has_escaping_regions());
-
- ty::Predicate::Trait(ty::Binder(ty::TraitPredicate {
+ ty::Predicate::Trait(ty::Binder::dummy(ty::TraitPredicate {
trait_ref: self.clone()
}))
}
ty::Predicate::Trait(ref data) => {
data.skip_binder().input_types().collect()
}
- ty::Predicate::Subtype(ty::Binder(SubtypePredicate { a, b, a_is_expected: _ })) => {
+ ty::Predicate::Subtype(binder) => {
+ let SubtypePredicate { a, b, a_is_expected: _ } = binder.skip_binder();
vec![a, b]
}
- ty::Predicate::TypeOutlives(ty::Binder(ref data)) => {
- vec![data.0]
+ ty::Predicate::TypeOutlives(binder) => {
+ vec![binder.skip_binder().0]
}
ty::Predicate::RegionOutlives(..) => {
vec![]
}
ty::Predicate::Projection(ref data) => {
- data.0.projection_ty.substs.types().chain(Some(data.0.ty)).collect()
+ let inner = data.skip_binder();
+ inner.projection_ty.substs.types().chain(Some(inner.ty)).collect()
}
ty::Predicate::WellFormed(data) => {
vec![data]
Some(x) => x,
_ => return vec![ty]
};
- let sized_predicate = Binder(TraitRef {
+ let sized_predicate = Binder::dummy(TraitRef {
def_id: sized_trait,
substs: tcx.mk_substs_trait(ty, &[])
}).to_predicate();
{
// Wrap our types with a temporary GeneratorWitness struct
// inside the binder so we can related them
- let a_types = ty::Binder(GeneratorWitness(*a_types.skip_binder()));
- let b_types = ty::Binder(GeneratorWitness(*b_types.skip_binder()));
+ let a_types = a_types.map_bound(GeneratorWitness);
+ let b_types = b_types.map_bound(GeneratorWitness);
// Then remove the GeneratorWitness for the result
- let types = ty::Binder(relation.relate(&a_types, &b_types)?.skip_binder().0);
+ let types = relation.relate(&a_types, &b_types)?.map_bound(|witness| witness.0);
Ok(tcx.mk_generator_witness(types))
}
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
type Lifted = ty::Binder<T::Lifted>;
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
- tcx.lift(&self.0).map(|x| ty::Binder(x))
+ tcx.lift(self.skip_binder()).map(ty::Binder::bind)
}
}
impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
- ty::Binder(self.0.fold_with(folder))
+ self.map_bound_ref(|ty| ty.fold_with(folder))
}
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
- self.0.visit_with(visitor)
+ self.skip_binder().visit_with(visitor)
}
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
/// binder, but it never contains bound regions. Probably this
/// function should be removed.
pub fn generator_poly_sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> PolyGenSig<'tcx> {
- ty::Binder(self.generator_sig(def_id, tcx))
+ ty::Binder::dummy(self.generator_sig(def_id, tcx))
}
/// Return the "generator signature", which consists of its yield
impl<'tcx> Binder<&'tcx Slice<ExistentialPredicate<'tcx>>> {
pub fn principal(&self) -> Option<PolyExistentialTraitRef<'tcx>> {
- self.skip_binder().principal().map(Binder)
+ self.skip_binder().principal().map(Binder::bind)
}
#[inline]
pub fn projection_bounds<'a>(&'a self) ->
impl Iterator<Item=PolyExistentialProjection<'tcx>> + 'a {
- self.skip_binder().projection_bounds().map(Binder)
+ self.skip_binder().projection_bounds().map(Binder::bind)
}
#[inline]
pub fn iter<'a>(&'a self)
-> impl DoubleEndedIterator<Item=Binder<ExistentialPredicate<'tcx>>> + 'tcx {
- self.skip_binder().iter().cloned().map(Binder)
+ self.skip_binder().iter().cloned().map(Binder::bind)
}
}
impl<'tcx> PolyTraitRef<'tcx> {
pub fn self_ty(&self) -> Ty<'tcx> {
- self.0.self_ty()
+ self.skip_binder().self_ty()
}
pub fn def_id(&self) -> DefId {
- self.0.def_id
- }
-
- pub fn substs(&self) -> &'tcx Substs<'tcx> {
- // FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
- self.0.substs
- }
-
- pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item=Ty<'tcx>> + 'a {
- // FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
- self.0.input_types()
+ self.skip_binder().def_id
}
pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
// Note that we preserve binding levels
- Binder(ty::TraitPredicate { trait_ref: self.0.clone() })
+ Binder(ty::TraitPredicate { trait_ref: self.skip_binder().clone() })
}
}
impl<'tcx> PolyExistentialTraitRef<'tcx> {
pub fn def_id(&self) -> DefId {
- self.0.def_id
- }
-
- pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item=Ty<'tcx>> + 'a {
- // FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
- self.0.input_types()
+ self.skip_binder().def_id
}
}
/// type from `Binder<T>` to just `T` (see
/// e.g. `liberate_late_bound_regions`).
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
-pub struct Binder<T>(pub T);
+pub struct Binder<T>(T);
impl<T> Binder<T> {
/// Wraps `value` in a binder, asserting that `value` does not
Binder(value)
}
+ /// Wraps `value` in a binder, binding late-bound regions (if any).
+ pub fn bind<'tcx>(value: T) -> Binder<T>
+ {
+ Binder(value)
+ }
+
/// Skips the binder and returns the "bound" value. This is a
/// risky thing to do because it's easy to get confused about
/// debruijn indices and the like. It is usually better to
}
pub fn as_ref(&self) -> Binder<&T> {
- ty::Binder(&self.0)
+ Binder(&self.0)
}
pub fn map_bound_ref<F, U>(&self, f: F) -> Binder<U>
pub fn map_bound<F, U>(self, f: F) -> Binder<U>
where F: FnOnce(T) -> U
{
- ty::Binder(f(self.0))
+ Binder(f(self.0))
}
/// Unwraps and returns the value within, but only if it contains
pub fn fuse<U,F,R>(self, u: Binder<U>, f: F) -> Binder<R>
where F: FnOnce(T, U) -> R
{
- ty::Binder(f(self.0, u.0))
+ Binder(f(self.0, u.0))
}
/// Split the contents into two things that share the same binder
where F: FnOnce(T) -> (U, V)
{
let (u, v) = f(self.0);
- (ty::Binder(u), ty::Binder(v))
+ (Binder(u), Binder(v))
}
}
impl<'tcx> PolyFnSig<'tcx> {
pub fn inputs(&self) -> Binder<&'tcx [Ty<'tcx>]> {
- Binder(self.skip_binder().inputs())
+ self.map_bound_ref(|fn_sig| fn_sig.inputs())
}
pub fn input(&self, index: usize) -> ty::Binder<Ty<'tcx>> {
self.map_bound_ref(|fn_sig| fn_sig.inputs()[index])
-> ty::PolyProjectionPredicate<'tcx> {
self.map_bound(|p| p.with_self_ty(tcx, self_ty))
}
+
+ pub fn item_def_id(&self) -> DefId {
+ return self.skip_binder().item_def_id;
+ }
}
impl DebruijnIndex {
ty::Predicate::ConstEvaluatable(..) => {
None
}
- ty::Predicate::TypeOutlives(ty::Binder(ty::OutlivesPredicate(t, r))) => {
+ ty::Predicate::TypeOutlives(predicate) => {
// Search for a bound of the form `erased_self_ty
// : 'a`, but be wary of something like `for<'a>
// erased_self_ty : 'a` (we interpret a
// it's kind of a moot point since you could never
// construct such an object, but this seems
// correct even if that code changes).
- if t == erased_self_ty && !r.has_escaping_regions() {
- Some(r)
+ let ty::OutlivesPredicate(ref t, ref r) = predicate.skip_binder();
+ if t == &erased_self_ty && !r.has_escaping_regions() {
+ Some(*r)
} else {
None
}
ty::ClosureKind::FnMut => self.mk_mut_ref(self.mk_region(env_region), closure_ty),
ty::ClosureKind::FnOnce => closure_ty,
};
- Some(ty::Binder(env_ty))
+ Some(ty::Binder::bind(env_ty))
}
/// Given the def-id of some item that has no type parameters, make
cause,
param_env,
ty::Predicate::TypeOutlives(
- ty::Binder(
+ ty::Binder::dummy(
ty::OutlivesPredicate(mt.ty, r)))));
}
}
for implicit_bound in implicit_bounds {
let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound));
- let outlives = ty::Binder(ty::OutlivesPredicate(explicit_bound, implicit_bound));
+ let outlives = ty::Binder::dummy(
+ ty::OutlivesPredicate(explicit_bound, implicit_bound));
self.out.push(traits::Obligation::new(cause,
self.param_env,
outlives.to_predicate()));
let value = if let Some(v) = lifted {
v
} else {
- return original.0.print_display(f, self);
+ return original.skip_binder().print_display(f, self);
};
if self.binder_depth == 0 {
ty::tls::with(|tcx| {
let dummy_self = tcx.mk_infer(ty::FreshTy(0));
- let trait_ref = tcx.lift(&ty::Binder(*self))
+ let trait_ref = *tcx.lift(&ty::Binder::bind(*self))
.expect("could not lift TraitRef for printing")
- .with_self_ty(tcx, dummy_self).0;
+ .with_self_ty(tcx, dummy_self).skip_binder();
cx.parameterized(f, trait_ref.substs, trait_ref.def_id, &[])
})
}
}
pub fn t_fn(&self, input_tys: &[Ty<'tcx>], output_ty: Ty<'tcx>) -> Ty<'tcx> {
- self.infcx.tcx.mk_fn_ptr(ty::Binder(self.infcx.tcx.mk_fn_sig(
+ self.infcx.tcx.mk_fn_ptr(ty::Binder::bind(self.infcx.tcx.mk_fn_sig(
input_tys.iter().cloned(),
output_ty,
false,
// Attempt to select a concrete impl before checking.
ty::TraitContainer(trait_def_id) => {
let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, callee_substs);
- let trait_ref = ty::Binder(trait_ref);
+ let trait_ref = ty::Binder::bind(trait_ref);
let span = tcx.hir.span(expr_id);
let obligation =
traits::Obligation::new(traits::ObligationCause::misc(span, expr_id),
-> CustomCoerceUnsized {
let def_id = tcx.lang_items().coerce_unsized_trait().unwrap();
- let trait_ref = ty::Binder(ty::TraitRef {
+ let trait_ref = ty::Binder::bind(ty::TraitRef {
def_id: def_id,
substs: tcx.mk_substs_trait(source_ty, &[target_ty])
});
}
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r1.into(), r2),
})
- .map(ty::Binder) // no bound regions in the code above
+ .map(ty::Binder::dummy) // no bound regions in the code above
.collect();
outlives.extend(
region_obligations
.into_iter()
.map(|(_, r_o)| ty::OutlivesPredicate(r_o.sup_type.into(), r_o.sub_region))
- .map(ty::Binder) // no bound regions in the code above
+ .map(ty::Binder::dummy) // no bound regions in the code above
);
outlives
return llfn;
}
- let ty = tcx.mk_fn_ptr(ty::Binder(tcx.mk_fn_sig(
+ let ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
tcx.types.never,
false,
output: Ty<'tcx>,
trans: &mut for<'b> FnMut(Builder<'b, 'tcx>))
-> ValueRef {
- let rust_fn_ty = cx.tcx.mk_fn_ptr(ty::Binder(cx.tcx.mk_fn_sig(
+ let rust_fn_ty = cx.tcx.mk_fn_ptr(ty::Binder::bind(cx.tcx.mk_fn_sig(
inputs.into_iter(),
output,
false,
// Define the type up front for the signature of the rust_try function.
let tcx = cx.tcx;
let i8p = tcx.mk_mut_ptr(tcx.types.i8);
- let fn_ty = tcx.mk_fn_ptr(ty::Binder(tcx.mk_fn_sig(
+ let fn_ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
iter::once(i8p),
tcx.mk_nil(),
false,
trait_def_id,
self_ty,
trait_ref.path.segments.last().unwrap());
- let poly_trait_ref = ty::Binder(ty::TraitRef::new(trait_def_id, substs));
+ let poly_trait_ref = ty::Binder::bind(ty::TraitRef::new(trait_def_id, substs));
poly_projections.extend(assoc_bindings.iter().filter_map(|binding| {
// specify type to assert that error was already reported in Err case:
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
let late_bound_in_trait_ref = tcx.collect_constrained_late_bound_regions(&trait_ref);
let late_bound_in_ty =
- tcx.collect_referenced_late_bound_regions(&ty::Binder(binding.ty));
+ tcx.collect_referenced_late_bound_regions(&ty::Binder::bind(binding.ty));
debug!("late_bound_in_trait_ref = {:?}", late_bound_in_trait_ref);
debug!("late_bound_in_ty = {:?}", late_bound_in_ty);
for br in late_bound_in_ty.difference(&late_bound_in_trait_ref) {
}
for projection_bound in &projection_bounds {
- associated_types.remove(&projection_bound.0.projection_ty.item_def_id);
+ associated_types.remove(&projection_bound.projection_def_id());
}
for item_def_id in associated_types {
.emit();
}
+ // skip_binder is okay, because the predicates are re-bound.
let mut v =
iter::once(ty::ExistentialPredicate::Trait(*existential_principal.skip_binder()))
.chain(auto_traits.into_iter().map(ty::ExistentialPredicate::AutoTrait))
.map(|x| ty::ExistentialPredicate::Projection(*x.skip_binder())))
.collect::<AccumulateVec<[_; 8]>>();
v.sort_by(|a, b| a.cmp(tcx, b));
- let existential_predicates = ty::Binder(tcx.mk_existential_predicates(v.into_iter()));
+ let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter()));
// Explicitly specified region bound. Use that.
};
let candidates =
- traits::supertraits(tcx, ty::Binder(trait_ref))
+ traits::supertraits(tcx, ty::Binder::bind(trait_ref))
.filter(|r| self.trait_defines_associated_type_named(r.def_id(),
assoc_name));
}
};
- let trait_did = bound.0.def_id;
+ let trait_did = bound.def_id();
let (assoc_ident, def_scope) = tcx.adjust(assoc_name, trait_did, ref_id);
let item = tcx.associated_items(trait_did).find(|i| {
Namespace::from(i.kind) == Namespace::Type &&
debug!("ty_of_fn: output_ty={:?}", output_ty);
- let bare_fn_ty = ty::Binder(tcx.mk_fn_sig(
+ let bare_fn_ty = ty::Binder::bind(tcx.mk_fn_sig(
input_tys.into_iter(),
output_ty,
decl.variadic,
// account for the binder being introduced below; no need to shift `param_ty`
// because, at present at least, it can only refer to early-bound regions
let region_bound = tcx.mk_region(ty::fold::shift_region(*region_bound, 1));
- vec.push(ty::Binder(ty::OutlivesPredicate(param_ty, region_bound)).to_predicate());
+ vec.push(
+ ty::Binder::dummy(ty::OutlivesPredicate(param_ty, region_bound)).to_predicate());
}
for bound_trait_ref in &self.trait_bounds {
// This is the "default" function signature, used in case of error.
// In that case, we check each argument against "error" in order to
// set up all the node type bindings.
- (ty::Binder(self.tcx.mk_fn_sig(
+ (ty::Binder::bind(self.tcx.mk_fn_sig(
self.err_args(arg_exprs.len()).into_iter(),
self.tcx.types.err,
false,
return None;
}
- let arg_param_ty = trait_ref.substs().type_at(1);
+ let arg_param_ty = trait_ref.skip_binder().substs.type_at(1);
let arg_param_ty = self.resolve_type_vars_if_possible(&arg_param_ty);
debug!(
"deduce_sig_from_projection: arg_param_ty {:?}",
}
};
- let ret_param_ty = projection.0.ty;
+ let ret_param_ty = projection.skip_binder().ty;
let ret_param_ty = self.resolve_type_vars_if_possible(&ret_param_ty);
debug!(
"deduce_sig_from_projection: ret_param_ty {:?}",
// regions appearing free in `expected_sig` are now bound up
// in this binder we are creating.
assert!(!expected_sig.sig.has_regions_escaping_depth(1));
- let bound_sig = ty::Binder(self.tcx.mk_fn_sig(
+ let bound_sig = ty::Binder::bind(self.tcx.mk_fn_sig(
expected_sig.sig.inputs().iter().cloned(),
expected_sig.sig.output(),
decl.variadic,
let (supplied_ty, _) = self.infcx.replace_late_bound_regions_with_fresh_var(
hir_ty.span,
LateBoundRegionConversionTime::FnCall,
- &ty::Binder(supplied_ty),
+ &ty::Binder::bind(supplied_ty),
); // recreated from (*) above
// Check that E' = S'.
hir::DefaultReturn(_) => astconv.ty_infer(decl.output.span()),
};
- let result = ty::Binder(self.tcx.mk_fn_sig(
+ let result = ty::Binder::bind(self.tcx.mk_fn_sig(
supplied_arguments,
supplied_return,
decl.variadic,
hir::DefaultReturn(_) => {}
}
- let result = ty::Binder(self.tcx.mk_fn_sig(
+ let result = ty::Binder::bind(self.tcx.mk_fn_sig(
supplied_arguments,
self.tcx.types.err,
decl.variadic,
let trait_ref = match obligation.predicate {
ty::Predicate::Trait(ref tr) if traits.contains(&tr.def_id()) => {
if unsize_did == tr.def_id() {
- if let ty::TyTuple(..) = tr.0.input_types().nth(1).unwrap().sty {
+ let sty = &tr.skip_binder().input_types().nth(1).unwrap().sty;
+ if let ty::TyTuple(..) = sty {
debug!("coerce_unsized: found unsized tuple coercion");
has_unsized_tuple_coercion = true;
}
let mut selcx = traits::SelectionContext::new(&infcx);
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_skol_substs);
- let (impl_m_own_bounds, _) = infcx.replace_late_bound_regions_with_fresh_var(impl_m_span,
- infer::HigherRankedType,
- &ty::Binder(impl_m_own_bounds.predicates));
+ let (impl_m_own_bounds, _) = infcx.replace_late_bound_regions_with_fresh_var(
+ impl_m_span,
+ infer::HigherRankedType,
+ &ty::Binder::bind(impl_m_own_bounds.predicates)
+ );
for predicate in impl_m_own_bounds {
let traits::Normalized { value: predicate, obligations } =
traits::normalize(&mut selcx, param_env, normalize_cause.clone(), &predicate);
impl_m_node_id,
param_env,
&impl_sig);
- let impl_fty = tcx.mk_fn_ptr(ty::Binder(impl_sig));
+ let impl_fty = tcx.mk_fn_ptr(ty::Binder::bind(impl_sig));
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
let trait_sig = tcx.liberate_late_bound_regions(
impl_m_node_id,
param_env,
&trait_sig);
- let trait_fty = tcx.mk_fn_ptr(ty::Binder(trait_sig));
+ let trait_fty = tcx.mk_fn_ptr(ty::Binder::bind(trait_sig));
debug!("compare_impl_method: trait_fty={:?}", trait_fty);
tcx.infer_ctxt().enter(|infcx| {
let self_arg_ty = tcx.liberate_late_bound_regions(
method.def_id,
- &ty::Binder(self_arg_ty)
+ &ty::Binder::bind(self_arg_ty)
);
let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty).is_ok();
match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
ty::BrAnon(counter)))
});
- let witness = fcx.tcx.mk_generator_witness(ty::Binder(type_list));
+ let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind(type_list));
debug!("Types in generator after region replacement {:?}, span = {:?}",
witness, body.value.span);
return;
}
- let fty = tcx.mk_fn_ptr(ty::Binder(tcx.mk_fn_sig(
+ let fty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
inputs.into_iter(),
output,
false,
"try" => {
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
- let fn_ty = ty::Binder(tcx.mk_fn_sig(
+ let fn_ty = ty::Binder::bind(tcx.mk_fn_sig(
iter::once(mut_u8),
tcx.mk_nil(),
false,
// We won't add these if we encountered an illegal sized bound, so that we can use
// a custom error in that case.
if !illegal_sized_bound {
- let method_ty = self.tcx.mk_fn_ptr(ty::Binder(method_sig));
+ let method_ty = self.tcx.mk_fn_ptr(ty::Binder::bind(method_sig));
self.add_obligations(method_ty, all_substs, &method_predicates);
}
}
})
.any(|trait_pred| {
- match trait_pred.0.self_ty().sty {
+ match trait_pred.skip_binder().self_ty().sty {
ty::TyDynamic(..) => true,
_ => false,
}
&bounds));
// Also add an obligation for the method type being well-formed.
- let method_ty = tcx.mk_fn_ptr(ty::Binder(fn_sig));
+ let method_ty = tcx.mk_fn_ptr(ty::Binder::bind(fn_sig));
debug!("lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}",
method_ty,
obligation);
.filter_map(|predicate| {
match *predicate {
ty::Predicate::Trait(ref trait_predicate) => {
- match trait_predicate.0.trait_ref.self_ty().sty {
+ match trait_predicate.skip_binder().trait_ref.self_ty().sty {
ty::TyParam(ref p) if *p == param_ty => {
Some(trait_predicate.to_poly_trait_ref())
}
if !selcx.evaluate_obligation(&o) {
result = ProbeResult::NoMatch;
if let &ty::Predicate::Trait(ref pred) = &o.predicate {
- possibly_unsatisfied_predicates.push(pred.0.trait_ref);
+ possibly_unsatisfied_predicates.push(pred.skip_binder().trait_ref);
}
}
}
// inference variables or other artifacts. This
// means they are safe to put into the
// `WhereClausePick`.
- assert!(!trait_ref.substs().needs_infer());
+ assert!(!trait_ref.skip_binder().substs.needs_infer());
WhereClausePick(trait_ref.clone())
}
predicates: self.param_env.caller_bounds.iter().filter(|predicate| {
match **predicate {
ty::Predicate::Trait(ref data) => {
- data.0.self_ty().is_param(index)
+ data.skip_binder().self_ty().is_param(index)
}
_ => false
}
let self_ty = fcx.normalize_associated_types_in(span, &self_ty);
let self_ty = fcx.tcx.liberate_late_bound_regions(
method.def_id,
- &ty::Binder(self_ty)
+ &ty::Binder::bind(self_ty)
);
let self_arg_ty = sig.inputs()[0];
let self_arg_ty = fcx.normalize_associated_types_in(span, &self_arg_ty);
let self_arg_ty = fcx.tcx.liberate_late_bound_regions(
method.def_id,
- &ty::Binder(self_arg_ty)
+ &ty::Binder::bind(self_arg_ty)
);
let mut autoderef = fcx.autoderef(span, self_arg_ty).include_raw_pointers();
let inputs = fields.iter().map(|f| {
tcx.type_of(tcx.hir.local_def_id(f.id))
});
- ty::Binder(tcx.mk_fn_sig(
+ ty::Binder::bind(tcx.mk_fn_sig(
inputs,
ty,
false,
for bound in ¶m.bounds {
let bound_region = AstConv::ast_region_to_region(&icx, bound, None);
- let outlives = ty::Binder(ty::OutlivesPredicate(region, bound_region));
+ let outlives = ty::Binder::bind(ty::OutlivesPredicate(region, bound_region));
predicates.push(outlives.to_predicate());
}
}
let region = AstConv::ast_region_to_region(&icx,
lifetime,
None);
- let pred = ty::Binder(ty::OutlivesPredicate(ty, region));
+ let pred = ty::Binder::bind(ty::OutlivesPredicate(ty, region));
predicates.push(ty::Predicate::TypeOutlives(pred))
}
}
let r1 = AstConv::ast_region_to_region(&icx, ®ion_pred.lifetime, None);
for bound in ®ion_pred.bounds {
let r2 = AstConv::ast_region_to_region(&icx, bound, None);
- let pred = ty::Binder(ty::OutlivesPredicate(r1, r2));
+ let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2));
predicates.push(ty::Predicate::RegionOutlives(pred))
}
}
}
hir::RegionTyParamBound(ref lifetime) => {
let region = astconv.ast_region_to_region(lifetime, None);
- let pred = ty::Binder(ty::OutlivesPredicate(param_ty, region));
+ let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region));
vec![ty::Predicate::TypeOutlives(pred)]
}
hir::TraitTyParamBound(_, hir::TraitBoundModifier::Maybe) => {
tcx.mk_nil()
};
- let se_ty = tcx.mk_fn_ptr(ty::Binder(
+ let se_ty = tcx.mk_fn_ptr(ty::Binder::bind(
tcx.mk_fn_sig(
iter::empty(),
expected_return_type,
_ => ()
}
- let se_ty = tcx.mk_fn_ptr(ty::Binder(
+ let se_ty = tcx.mk_fn_ptr(ty::Binder::bind(
tcx.mk_fn_sig(
[
tcx.types.isize,
// where OutlivesPredicate<type1, region1> is the predicate
// we want to add.
ty::Predicate::TypeOutlives(poly) => {
- let predicate = poly.0.subst(tcx, substs);
+ let predicate = poly.skip_binder().subst(tcx, substs);
insert_outlives_predicate(
tcx,
predicate.0.into(),
// where OutlivesPredicate<region1, region2> is the predicate
// we want to add.
ty::Predicate::RegionOutlives(poly) => {
- let predicate = poly.0.subst(tcx, substs);
+ let predicate = poly.skip_binder().subst(tcx, substs);
insert_outlives_predicate(
tcx,
predicate.0.into(),
let vec: Vec<ty::Predicate<'tcx>> = set.iter()
.map(
|ty::OutlivesPredicate(kind1, region2)| match kind1.unpack() {
- UnpackedKind::Type(ty1) => ty::Predicate::TypeOutlives(ty::Binder(
+ UnpackedKind::Type(ty1) => ty::Predicate::TypeOutlives(ty::Binder::bind(
ty::OutlivesPredicate(ty1, region2),
)),
UnpackedKind::Lifetime(region1) => ty::Predicate::RegionOutlives(
- ty::Binder(ty::OutlivesPredicate(region1, region2)),
+ ty::Binder::bind(ty::OutlivesPredicate(region1, region2)),
),
},
)
if let Some(p) = data.principal() {
let poly_trait_ref = p.with_self_ty(self.tcx(), self.tcx().types.err);
- self.add_constraints_from_trait_ref(current, poly_trait_ref.0, variance);
+ self.add_constraints_from_trait_ref(
+ current, *poly_trait_ref.skip_binder(), variance);
}
for projection in data.projection_bounds() {
- self.add_constraints_from_ty(current, projection.0.ty, self.invariant);
+ self.add_constraints_from_ty(
+ current, projection.skip_binder().ty, self.invariant);
}
}
sig: ty::PolyFnSig<'tcx>,
variance: VarianceTermPtr<'a>) {
let contra = self.contravariant(variance);
- for &input in sig.0.inputs() {
+ for &input in sig.skip_binder().inputs() {
self.add_constraints_from_ty(current, input, contra);
}
- self.add_constraints_from_ty(current, sig.0.output(), variance);
+ self.add_constraints_from_ty(current, sig.skip_binder().output(), variance);
}
/// Adds constraints appropriate for a region appearing in a
substs: tcx.mk_substs_trait(ty, &[]),
};
- let trait_pred = ty::Binder(trait_ref);
+ let trait_pred = ty::Binder::bind(trait_ref);
let bail_out = tcx.infer_ctxt().enter(|infcx| {
let mut selcx = SelectionContext::with_negative(&infcx, true);
let mut already_visited = FxHashSet();
let mut predicates = VecDeque::new();
- predicates.push_back(ty::Binder(ty::TraitPredicate {
+ predicates.push_back(ty::Binder::bind(ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: trait_did,
substs: infcx.tcx.mk_substs_trait(ty, &[]),
impl<T, U> Clean<U> for ty::Binder<T> where T: Clean<U> {
fn clean(&self, cx: &DocContext) -> U {
- self.0.clean(cx)
+ self.skip_binder().clean(cx)
}
}
}
let mut bindings = vec![];
- for ty::Binder(ref pb) in obj.projection_bounds() {
+ for pb in obj.projection_bounds() {
bindings.push(TypeBinding {
- name: cx.tcx.associated_item(pb.item_def_id).name.clean(cx),
- ty: pb.ty.clean(cx)
+ name: cx.tcx.associated_item(pb.item_def_id()).name.clean(cx),
+ ty: pb.skip_binder().ty.clean(cx)
});
}
let path = external_path(cx, &cx.tcx.item_name(did), Some(did),
- false, bindings, principal.0.substs);
+ false, bindings, principal.skip_binder().substs);
ResolvedPath {
path,
typarams: Some(typarams),
let predicates = cx.tcx.super_predicates_of(child).predicates;
predicates.iter().filter_map(|pred| {
if let ty::Predicate::Trait(ref pred) = *pred {
- if pred.0.trait_ref.self_ty().is_self() {
+ if pred.skip_binder().trait_ref.self_ty().is_self() {
Some(pred.def_id())
} else {
None