debug!(?substs_trait_ref_and_assoc_item);
- ty::AliasTy { def_id: assoc_item.def_id, substs: substs_trait_ref_and_assoc_item }
+ self.tcx().mk_alias_ty(assoc_item.def_id, substs_trait_ref_and_assoc_item)
});
if !speculative {
_ => predicates.push(
ty::Binder::bind_with_vars(
ty::ProjectionPredicate {
- projection_ty: ty::AliasTy {
- def_id: trait_ty.def_id,
- substs: rebased_substs,
- },
+ projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_substs),
term: impl_ty_value.into(),
},
bound_vars,
.chain(projection_ty.substs.iter().skip(1)),
);
- let quiet_projection_ty = ty::AliasTy {
- substs: substs_with_infer_self,
- def_id: projection_ty.def_id,
- };
+ let quiet_projection_ty =
+ tcx.mk_alias_ty(projection_ty.def_id, substs_with_infer_self);
let term = pred.skip_binder().term;
use crate::traits;
use crate::ty::query::{self, TyCtxtAt};
use crate::ty::{
- self, AdtDef, AdtDefData, AdtKind, AliasTy, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
+ self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
ClosureSizeProfileData, Const, ConstS, DefIdTree, FloatTy, FloatVar, FloatVid,
GenericParamDefKind, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy,
PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, RegionKind, ReprOptions,
#[inline]
pub fn mk_projection(self, item_def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
- debug_assert_eq!(
- self.generics_of(item_def_id).count(),
- substs.len(),
- "wrong number of generic parameters for {item_def_id:?}: {substs:?}",
- );
- self.mk_ty(Alias(ty::Projection, AliasTy { def_id: item_def_id, substs }))
+ self.mk_ty(Alias(ty::Projection, self.mk_alias_ty(item_def_id, substs)))
}
#[inline]
ty::TraitRef::new(trait_def_id, substs)
}
+ pub fn mk_alias_ty(
+ self,
+ def_id: DefId,
+ substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
+ ) -> ty::AliasTy<'tcx> {
+ let substs = substs.into_iter().map(Into::into);
+ let n = self.generics_of(def_id).count();
+ debug_assert_eq!(
+ (n, Some(n)),
+ substs.size_hint(),
+ "wrong number of generic parameters for {def_id:?}: {:?} \nDid you accidentally include the self-type in the params list?",
+ substs.collect::<Vec<_>>(),
+ );
+ let substs = self.mk_substs(substs);
+ ty::AliasTy { def_id, substs }
+ }
+
pub fn mk_bound_variable_kinds<
I: InternAs<ty::BoundVariableKind, &'tcx List<ty::BoundVariableKind>>,
>(
Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id)))
} else {
let substs = relation.relate(a.substs, b.substs)?;
- Ok(ty::AliasTy { def_id: a.def_id, substs: &substs })
+ Ok(relation.tcx().mk_alias_ty(a.def_id, substs))
}
}
}
debug_assert!(!self_ty.has_escaping_bound_vars());
ty::ProjectionPredicate {
- projection_ty: ty::AliasTy {
- def_id: self.def_id,
- substs: tcx.mk_substs_trait(self_ty, self.substs),
- },
+ projection_ty: tcx
+ .mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs)),
term: self.term,
}
}
// in. For example, this would be what `Iterator::Item` is here.
let ty_var = self.infcx.next_ty_var(origin);
// This corresponds to `<ExprTy as Iterator>::Item = _`.
- let trait_ref = ty::Binder::dummy(ty::PredicateKind::Clause(
+ let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
ty::Clause::Projection(ty::ProjectionPredicate {
- projection_ty: ty::AliasTy { substs, def_id: proj.def_id },
+ projection_ty: tcx.mk_alias_ty(proj.def_id, substs),
term: ty_var.into(),
}),
));
span,
expr.hir_id,
param_env,
- trait_ref,
+ projection,
));
if ocx.select_where_possible().is_empty() {
// `ty_var` now holds the type that `Item` is for `ExprTy`.
};
ty::ProjectionPredicate {
- projection_ty: ty::AliasTy {
- substs: trait_ref.substs,
- def_id: obligation.predicate.def_id,
- },
+ projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.substs),
term: ty.into(),
}
});
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
ty::ProjectionPredicate {
- projection_ty: ty::AliasTy {
- substs: trait_ref.substs,
- def_id: obligation.predicate.def_id,
- },
+ projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.substs),
term: return_ty.into(),
}
});
bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate);
};
- let predicate = ty::ProjectionPredicate {
- projection_ty: ty::AliasTy { substs, def_id: item_def_id },
- term,
- };
+ let predicate =
+ ty::ProjectionPredicate { projection_ty: tcx.mk_alias_ty(item_def_id, substs), term };
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
.with_addl_obligations(obligations)
flag,
)
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
- projection_ty: ty::AliasTy { substs: trait_ref.substs, def_id: fn_once_output_def_id },
+ projection_ty: tcx.mk_alias_ty(fn_once_output_def_id, trait_ref.substs),
term: ret_type.into(),
});
let ty = traits::normalize_projection_type(
self,
param_env,
- ty::AliasTy { def_id: tcx.lang_items().deref_target()?, substs: trait_ref.substs },
+ tcx.mk_alias_ty(tcx.lang_items().deref_target()?, trait_ref.substs),
cause.clone(),
0,
// We're *intentionally* throwing these away,