use hir::def_id::DefId;
use infer;
use infer::{InferCtxt, InferOk, TypeFreshener, TypeOrigin};
-use ty::subst::{Subst, Substs};
+use ty::subst::{Kind, Subst, Substs};
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
use traits;
use ty::fast_reject;
}
match obligation.predicate {
- ty::Predicate::Rfc1592(..) => EvaluatedToOk,
-
ty::Predicate::Trait(ref t) => {
assert!(!t.has_escaping_regions());
let obligation = obligation.with(t.clone());
// This suffices to allow chains like `FnMut` implemented in
// terms of `Fn` etc, but we could probably make this more
// precise still.
- let input_types = stack.fresh_trait_ref.0.input_types();
- let unbound_input_types = input_types.iter().any(|ty| ty.is_fresh());
+ let unbound_input_types = stack.fresh_trait_ref.input_types().any(|ty| ty.is_fresh());
if unbound_input_types && self.intercrate {
debug!("evaluate_stack({:?}) --> unbound argument, intercrate --> ambiguous",
stack.fresh_trait_ref);
match *candidate {
Ok(Some(_)) | Err(_) => true,
- Ok(None) => {
- cache_fresh_trait_pred.0.trait_ref.substs.types.has_infer_types()
- }
+ Ok(None) => cache_fresh_trait_pred.has_infer_types()
}
}
obligation: &TraitObligation<'tcx>,
trait_bound: ty::PolyTraitRef<'tcx>,
skol_trait_ref: ty::TraitRef<'tcx>,
- skol_map: &infer::SkolemizationMap,
+ skol_map: &infer::SkolemizationMap<'tcx>,
snapshot: &infer::CombinedSnapshot)
-> bool
{
return;
}
};
- let target = obligation.predicate.skip_binder().input_types()[1];
+ let target = obligation.predicate.skip_binder().trait_ref.substs.type_at(1);
debug!("assemble_candidates_for_unsizing(source={:?}, target={:?})",
source, target);
ty::TyStr | ty::TySlice(_) | ty::TyTrait(..) => Never,
ty::TyTuple(tys) => {
- // FIXME(#33242) we only need to constrain the last field
- Where(ty::Binder(tys.to_vec()))
+ Where(ty::Binder(tys.last().into_iter().cloned().collect()))
}
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
// for `PhantomData<T>`, we pass `T`
ty::TyStruct(def, substs) if def.is_phantom_data() => {
- substs.types.to_vec()
+ substs.types().collect()
}
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
trait_def_id,
recursion_depth,
normalized_ty,
- vec![]);
+ &[]);
obligations.push(skol_obligation);
this.infcx().plug_leaks(skol_map, snapshot, &obligations)
})
match self_ty.sty {
ty::TyTrait(ref data) => {
// OK to skip the binder, it is reintroduced below
- let input_types = data.principal.skip_binder().input_types();
+ let input_types = data.principal.input_types();
let assoc_types = data.projection_bounds.iter()
.map(|pb| pb.skip_binder().ty);
- let all_types: Vec<_> = input_types.iter().cloned()
- .chain(assoc_types)
- .collect();
+ let all_types: Vec<_> = input_types.chain(assoc_types)
+ .collect();
// reintroduce the two binding levels we skipped, then flatten into one
let all_types = ty::Binder(ty::Binder(all_types));
mut substs: Normalized<'tcx, &'tcx Substs<'tcx>>,
cause: ObligationCause<'tcx>,
recursion_depth: usize,
- skol_map: infer::SkolemizationMap,
+ skol_map: infer::SkolemizationMap<'tcx>,
snapshot: &infer::CombinedSnapshot)
-> VtableImplData<'tcx, PredicateObligation<'tcx>>
{
// regions here. See the comment there for more details.
let source = self.infcx.shallow_resolve(
tcx.no_late_bound_regions(&obligation.self_ty()).unwrap());
- let target = obligation.predicate.skip_binder().input_types()[1];
+ let target = obligation.predicate.skip_binder().trait_ref.substs.type_at(1);
let target = self.infcx.shallow_resolve(target);
debug!("confirm_builtin_unsize_candidate(source={:?}, target={:?})",
// T -> Trait.
(_, &ty::TyTrait(ref data)) => {
- let mut object_dids = Some(data.principal.def_id()).into_iter();
- // FIXME(#33243)
-// data.builtin_bounds.iter().flat_map(|bound| {
-// tcx.lang_items.from_builtin_kind(bound).ok()
-// })
-// .chain(Some(data.principal.def_id()));
+ let mut object_dids =
+ data.builtin_bounds.iter().flat_map(|bound| {
+ tcx.lang_items.from_builtin_kind(bound).ok()
+ })
+ .chain(Some(data.principal.def_id()));
if let Some(did) = object_dids.find(|did| {
!tcx.is_object_safe(*did)
}) {
} else {
return Err(Unimplemented);
};
- let mut ty_params = BitVector::new(substs_a.types.len());
+ let mut ty_params = BitVector::new(substs_a.types().count());
let mut found = false;
for ty in field.walk() {
if let ty::TyParam(p) = ty.sty {
// TyError and ensure they do not affect any other fields.
// This could be checked after type collection for any struct
// with a potentially unsized trailing field.
- let types = substs_a.types.iter().enumerate().map(|(i, ty)| {
+ let params = substs_a.params().iter().enumerate().map(|(i, &k)| {
if ty_params.contains(i) {
- tcx.types.err
+ Kind::from(tcx.types.err)
} else {
- ty
+ k
}
- }).collect();
- let substs = Substs::new(tcx, types, substs_a.regions.clone());
+ });
+ let substs = Substs::new(tcx, params);
for &ty in fields.split_last().unwrap().1 {
if ty.subst(tcx, substs).references_error() {
return Err(Unimplemented);
// Check that the source structure with the target's
// type parameters is a subtype of the target.
- let types = substs_a.types.iter().enumerate().map(|(i, ty)| {
+ let params = substs_a.params().iter().enumerate().map(|(i, &k)| {
if ty_params.contains(i) {
- substs_b.types[i]
+ Kind::from(substs_b.type_at(i))
} else {
- ty
+ k
}
- }).collect();
- let substs = Substs::new(tcx, types, substs_a.regions.clone());
- let new_struct = tcx.mk_struct(def, substs);
+ });
+ let new_struct = tcx.mk_struct(def, Substs::new(tcx, params));
let origin = TypeOrigin::Misc(obligation.cause.span);
let InferOk { obligations, .. } =
self.infcx.sub_types(false, origin, new_struct, target)
obligation.predicate.def_id(),
obligation.recursion_depth + 1,
inner_source,
- vec![inner_target]));
+ &[inner_target]));
}
_ => bug!()
impl_def_id: DefId,
obligation: &TraitObligation<'tcx>,
snapshot: &infer::CombinedSnapshot)
- -> (Normalized<'tcx, &'tcx Substs<'tcx>>, infer::SkolemizationMap)
+ -> (Normalized<'tcx, &'tcx Substs<'tcx>>,
+ infer::SkolemizationMap<'tcx>)
{
match self.match_impl(impl_def_id, obligation, snapshot) {
Ok((substs, skol_map)) => (substs, skol_map),
obligation: &TraitObligation<'tcx>,
snapshot: &infer::CombinedSnapshot)
-> Result<(Normalized<'tcx, &'tcx Substs<'tcx>>,
- infer::SkolemizationMap), ()>
+ infer::SkolemizationMap<'tcx>), ()>
{
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
// substitution if we find that any of the input types, when
// simplified, do not match.
- obligation.predicate.0.input_types().iter()
+ obligation.predicate.skip_binder().input_types()
.zip(impl_trait_ref.input_types())
- .any(|(&obligation_ty, &impl_ty)| {
+ .any(|(obligation_ty, impl_ty)| {
let simplified_obligation_ty =
fast_reject::simplify_type(self.tcx(), obligation_ty, true);
let simplified_impl_ty =
recursion_depth: usize,
def_id: DefId, // of impl or trait
substs: &Substs<'tcx>, // for impl or trait
- skol_map: infer::SkolemizationMap,
+ skol_map: infer::SkolemizationMap<'tcx>,
snapshot: &infer::CombinedSnapshot)
-> Vec<PredicateObligation<'tcx>>
{