&& fallback_has_occurred
{
let predicate = trait_predicate.map_bound(|mut trait_pred| {
- {
- let trait_ref = &mut trait_pred.trait_ref;
- let never_substs = trait_ref.substs;
- let mut unit_substs = Vec::with_capacity(never_substs.len());
- unit_substs.push(self.tcx.mk_nil().into());
- unit_substs.extend(&never_substs[1..]);
- trait_ref.substs = self.tcx.intern_substs(&unit_substs);
- }
+ trait_pred.trait_ref.substs = self.tcx.mk_substs_trait(
+ self.tcx.mk_nil(),
+ &trait_pred.trait_ref.substs[1..],
+ );
trait_pred
});
let unit_obligation = Obligation {
obligation.predicate.def_id(),
obligation.recursion_depth + 1,
inner_source,
- &[inner_target]));
+ &[inner_target.into()]));
}
// (.., T) -> (.., U).
assert_eq!(tys_a.len(), tys_b.len());
// The last field of the tuple has to exist.
- let (a_last, a_mid) = if let Some(x) = tys_a.split_last() {
+ let (&a_last, a_mid) = if let Some(x) = tys_a.split_last() {
x
} else {
return Err(Unimplemented);
};
- let b_last = tys_b.last().unwrap();
+ let &b_last = tys_b.last().unwrap();
// Check that the source tuple with the target's
// last element is equal to the target.
- let new_tuple = tcx.mk_tup(a_mid.iter().chain(Some(b_last)));
+ let new_tuple = tcx.mk_tup(a_mid.iter().cloned().chain(iter::once(b_last)));
let InferOk { obligations, .. } =
self.infcx.at(&obligation.cause, obligation.param_env)
.eq(target, new_tuple)
obligation.predicate.def_id(),
obligation.recursion_depth + 1,
a_last,
- &[b_last]));
+ &[b_last.into()]));
}
_ => bug!()
// except according to those terms.
use hir::def_id::DefId;
-use ty::subst::{Subst, Substs};
+use ty::subst::{Kind, Subst, Substs};
use ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef};
use ty::outlives::Component;
use util::nodemap::FxHashSet;
cause: ObligationCause<'tcx>,
trait_def_id: DefId,
recursion_depth: usize,
- param_ty: Ty<'tcx>,
- ty_params: &[Ty<'tcx>])
+ self_ty: Ty<'tcx>,
+ params: &[Kind<'tcx>])
-> PredicateObligation<'tcx>
{
let trait_ref = ty::TraitRef {
def_id: trait_def_id,
- substs: self.mk_substs_trait(param_ty, ty_params)
+ substs: self.mk_substs_trait(self_ty, params)
};
predicate_for_trait_ref(cause, param_env, trait_ref, recursion_depth)
}
};
let trait_ref = ty::TraitRef {
def_id: fn_trait_def_id,
- substs: self.mk_substs_trait(self_ty, &[arguments_tuple]),
+ substs: self.mk_substs_trait(self_ty, &[arguments_tuple.into()]),
};
ty::Binder::bind((trait_ref, sig.skip_binder().output()))
}
}
pub fn mk_substs_trait(self,
- s: Ty<'tcx>,
- t: &[Ty<'tcx>])
+ self_ty: Ty<'tcx>,
+ rest: &[Kind<'tcx>])
-> &'tcx Substs<'tcx>
{
- self.mk_substs(iter::once(s).chain(t.into_iter().cloned()).map(Kind::from))
+ self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned()))
}
pub fn mk_clauses<I: InternAs<[Clause<'tcx>], Clauses<'tcx>>>(self, iter: I) -> I::Output {
use hir::def_id::DefId;
use ty::{self, Ty, TypeFoldable, Substs, TyCtxt};
-use ty::subst::Kind;
use traits;
use rustc_target::spec::abi::Abi;
use util::ppaux;
let sig = substs.closure_sig(closure_did, tcx);
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
assert_eq!(sig.inputs().len(), 1);
- let substs = tcx.mk_substs([Kind::from(self_ty), sig.inputs()[0].into()].iter().cloned());
+ let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
debug!("fn_once_adapter_shim: self_ty={:?} sig={:?}", self_ty, sig);
Instance { def, substs }
// associated types.
self.substs.types()
}
+
+ pub fn from_method(tcx: TyCtxt<'_, '_, 'tcx>,
+ trait_id: DefId,
+ substs: &Substs<'tcx>)
+ -> ty::TraitRef<'tcx> {
+ let defs = tcx.generics_of(trait_id);
+
+ ty::TraitRef {
+ def_id: trait_id,
+ substs: tcx.intern_substs(&substs[..defs.params.len()])
+ }
+ }
}
pub type PolyTraitRef<'tcx> = Binder<TraitRef<'tcx>>;
self.substs.types()
}
+ pub fn erase_self_ty(tcx: TyCtxt<'a, 'gcx, 'tcx>,
+ trait_ref: ty::TraitRef<'tcx>)
+ -> ty::ExistentialTraitRef<'tcx> {
+ // Assert there is a Self.
+ trait_ref.substs.type_at(0);
+
+ ty::ExistentialTraitRef {
+ def_id: trait_ref.def_id,
+ substs: tcx.intern_substs(&trait_ref.substs[1..])
+ }
+ }
+
/// Object types don't have a self-type specified. Therefore, when
/// we convert the principal trait-ref into a normal trait-ref,
/// you must give *some* self-type. A common choice is `mk_err()`
ty::TraitRef {
def_id: self.def_id,
- substs: tcx.mk_substs(
- iter::once(self_ty.into()).chain(self.substs.iter().cloned()))
+ substs: tcx.mk_substs_trait(self_ty, self.substs)
}
}
}
pub fn def_id(&self) -> DefId {
self.skip_binder().def_id
}
+
+ /// Object types don't have a self-type specified. Therefore, when
+ /// we convert the principal trait-ref into a normal trait-ref,
+ /// you must give *some* self-type. A common choice is `mk_err()`
+ /// or some skolemized type.
+ pub fn with_self_ty(&self, tcx: TyCtxt<'_, '_, 'tcx>,
+ self_ty: Ty<'tcx>)
+ -> ty::PolyTraitRef<'tcx> {
+ self.map_bound(|trait_ref| trait_ref.with_self_ty(tcx, self_ty))
+ }
}
/// Binder is a binder for higher-ranked lifetimes. It is part of the
ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy {
item_def_id: self.item_def_id,
- substs: tcx.mk_substs(
- iter::once(self_ty.into()).chain(self.substs.iter().cloned())),
+ substs: tcx.mk_substs_trait(self_ty, self.substs),
},
ty: self.ty,
}
use core::intrinsics;
use std::fmt;
-use std::iter;
use std::marker::PhantomData;
use std::mem;
use std::num::NonZeroUsize;
self.tcx().mk_region(ty::fold::shift_region(*region, self.region_binders_passed))
}
}
-
-// Helper methods that modify substitutions.
-
-impl<'a, 'gcx, 'tcx> ty::TraitRef<'tcx> {
- pub fn from_method(tcx: TyCtxt<'a, 'gcx, 'tcx>,
- trait_id: DefId,
- substs: &Substs<'tcx>)
- -> ty::TraitRef<'tcx> {
- let defs = tcx.generics_of(trait_id);
-
- ty::TraitRef {
- def_id: trait_id,
- substs: tcx.intern_substs(&substs[..defs.params.len()])
- }
- }
-}
-
-impl<'a, 'gcx, 'tcx> ty::ExistentialTraitRef<'tcx> {
- pub fn erase_self_ty(tcx: TyCtxt<'a, 'gcx, 'tcx>,
- trait_ref: ty::TraitRef<'tcx>)
- -> ty::ExistentialTraitRef<'tcx> {
- // Assert there is a Self.
- trait_ref.substs.type_at(0);
-
- ty::ExistentialTraitRef {
- def_id: trait_ref.def_id,
- substs: tcx.intern_substs(&trait_ref.substs[1..])
- }
- }
-}
-
-impl<'a, 'gcx, 'tcx> ty::PolyExistentialTraitRef<'tcx> {
- /// Object types don't have a self-type specified. Therefore, when
- /// we convert the principal trait-ref into a normal trait-ref,
- /// you must give *some* self-type. A common choice is `mk_err()`
- /// or some skolemized type.
- pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
- self_ty: Ty<'tcx>)
- -> ty::PolyTraitRef<'tcx> {
- // otherwise the escaping regions would be captured by the binder
- assert!(!self_ty.has_escaping_regions());
-
- self.map_bound(|trait_ref| {
- ty::TraitRef {
- def_id: trait_ref.def_id,
- substs: tcx.mk_substs(
- iter::once(self_ty.into()).chain(trait_ref.substs.iter().cloned()))
- }
- })
- }
-}
}
CastKind::Unsize => {
+ let &ty = ty;
let trait_ref = ty::TraitRef {
def_id: tcx.lang_items().coerce_unsized_trait().unwrap(),
- substs: tcx.mk_substs_trait(op.ty(mir, tcx), &[ty]),
+ substs: tcx.mk_substs_trait(op.ty(mir, tcx), &[ty.into()]),
};
self.prove_trait_ref(trait_ref, location);
},
}
let eq_def_id = self.hir.tcx().lang_items().eq_trait().unwrap();
- let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty]);
+ let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty.into()]);
// take the argument by reference
let region_scope = self.topmost_scope();
use rustc::ty::layout::{IntegerExt, Size};
use rustc::ty::subst::Subst;
use rustc::ty::{self, Ty, TyCtxt, layout};
-use rustc::ty::subst::Substs;
+use rustc::ty::subst::{Kind, Substs};
use syntax::ast::{self, LitKind};
use syntax::attr;
use syntax::symbol::Symbol;
trait_def_id: DefId,
method_name: &str,
self_ty: Ty<'tcx>,
- params: &[Ty<'tcx>])
+ params: &[Kind<'tcx>])
-> (Ty<'tcx>, Literal<'tcx>) {
let method_name = Symbol::intern(method_name);
let substs = self.tcx.mk_substs_trait(self_ty, params);
use rustc::middle::lang_items::DropInPlaceFnLangItem;
use rustc::traits;
use rustc::ty::adjustment::CustomCoerceUnsized;
-use rustc::ty::subst::Kind;
use rustc::ty::{self, Ty, TyCtxt};
pub use rustc::ty::Instance;
let sig = substs.closure_sig(closure_did, tcx);
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
assert_eq!(sig.inputs().len(), 1);
- let substs = tcx.mk_substs([
- Kind::from(self_ty),
- sig.inputs()[0].into(),
- ].iter().cloned());
+ let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
debug!("fn_once_adapter_shim: self_ty={:?} sig={:?}", self_ty, sig);
Instance { def, substs }
let trait_ref = ty::Binder::bind(ty::TraitRef {
def_id: def_id,
- substs: tcx.mk_substs_trait(source_ty, &[target_ty])
+ substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()])
});
match tcx.codegen_fulfill_obligation( (ty::ParamEnv::reveal_all(), trait_ref)) {
use rustc::middle::lang_items;
use rustc::traits::Reveal;
use rustc::ty::{self, Ty, TyCtxt};
-use rustc::ty::subst::{Kind, Substs};
+use rustc::ty::subst::Substs;
use rustc::ty::util::IntTypeExt;
use rustc_data_structures::indexed_vec::Idx;
use util::patch::MirPatch;
-use std::{iter, u32};
+use std::u32;
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum DropFlagState {
let drop_trait = tcx.lang_items().drop_trait().unwrap();
let drop_fn = tcx.associated_items(drop_trait).next().unwrap();
let ty = self.place_ty(self.place);
- let substs = tcx.mk_substs(iter::once(Kind::from(ty)));
+ let substs = tcx.mk_substs_trait(ty, &[]);
let ref_ty = tcx.mk_ref(tcx.types.re_erased, ty::TypeAndMut {
ty,
coerce_unsized_did,
0,
coerce_source,
- &[coerce_target]));
+ &[coerce_target.into()]));
let mut has_unsized_tuple_coercion = false;
self.autoderef(span, ty).any(|(ty, _)| {
self.probe(|_| {
- let fn_once_substs = tcx.mk_substs_trait(ty,
- &[self.next_ty_var(TypeVariableOrigin::MiscVariable(span))]);
+ let fn_once_substs = tcx.mk_substs_trait(ty, &[
+ self.next_ty_var(TypeVariableOrigin::MiscVariable(span)).into()
+ ]);
let trait_ref = ty::TraitRef::new(fn_once, fn_once_substs);
let poly_trait_ref = trait_ref.to_poly_trait_ref();
let obligation =
use std::cmp;
use std::fmt::Display;
use std::mem::replace;
-use std::iter;
use std::ops::{self, Deref};
use rustc_target::spec::abi::Abi;
use syntax::ast;
if id == fn_id {
match entry_type {
config::EntryMain => {
- let substs = fcx.tcx.mk_substs(iter::once(Kind::from(declared_ret_ty)));
+ let substs = fcx.tcx.mk_substs_trait(declared_ret_ty, &[]);
let trait_ref = ty::TraitRef::new(term_id, substs);
let return_ty_span = decl.output.span();
let cause = traits::ObligationCause::new(
trait_def_id,
0,
source,
- &[target]);
+ &[target.into()]);
fulfill_cx.register_predicate_obligation(&infcx, predicate);
// Check that all transitive obligations are satisfied.