/// ```
FnPtr(PolyFnSig<'tcx>),
- /// A trait, defined with `trait`.
+ /// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`.
Dynamic(&'tcx List<Binder<ExistentialPredicate<'tcx>>>, ty::Region<'tcx>),
/// The anonymous type of a closure. Used to represent the type of
}
// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.
-#[cfg(target_arch = "x86_64")]
+#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(TyKind<'_>, 24);
/// A closure can be modeled as a struct that looks like:
Binder(value)
}
- /// Wraps `value` in a binder without actually binding any currently
- /// unbound variables.
- ///
- /// Note that this will shift all debrujin indices of escaping bound variables
- /// by 1 to avoid accidential captures.
- pub fn wrap_nonbinding(tcx: TyCtxt<'tcx>, value: T) -> Binder<T>
- where
- T: TypeFoldable<'tcx>,
- {
- if value.has_escaping_bound_vars() {
- Binder::bind(super::fold::shift_vars(tcx, value, 1))
- } else {
- Binder::dummy(value)
- }
- }
-
/// Skips the binder and returns the "bound" value. This is a
/// risky thing to do because it's easy to get confused about
/// De Bruijn indices and the like. It is usually better to
pub type PolyGenSig<'tcx> = Binder<GenSig<'tcx>>;
-impl<'tcx> PolyGenSig<'tcx> {
- pub fn resume_ty(&self) -> ty::Binder<Ty<'tcx>> {
- self.map_bound_ref(|sig| sig.resume_ty)
- }
- pub fn yield_ty(&self) -> ty::Binder<Ty<'tcx>> {
- self.map_bound_ref(|sig| sig.yield_ty)
- }
- pub fn return_ty(&self) -> ty::Binder<Ty<'tcx>> {
- self.map_bound_ref(|sig| sig.return_ty)
- }
-}
-
/// Signature of a function type, which we have arbitrarily
/// decided to use to refer to the input/output types.
///
ParamTy { index, name }
}
- pub fn for_self() -> ParamTy {
- ParamTy::new(0, kw::SelfUpper)
- }
-
pub fn for_def(def: &ty::GenericParamDef) -> ParamTy {
ParamTy::new(def.index, def.name)
}
pub name: Symbol,
}
-impl<'tcx> ParamConst {
+impl ParamConst {
pub fn new(index: u32, name: Symbol) -> ParamConst {
ParamConst { index, name }
}
pub fn for_def(def: &ty::GenericParamDef) -> ParamConst {
ParamConst::new(def.index, def.name)
}
-
- pub fn to_const(self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
- tcx.mk_const_param(self.index, self.name, ty)
- }
}
pub type Region<'tcx> = &'tcx RegionKind;
}
}
- /// Adjusts any De Bruijn indices so as to make `to_binder` the
- /// innermost binder. That is, if we have something bound at `to_binder`,
- /// it will now be bound at INNERMOST. This is an appropriate thing to do
- /// when moving a region out from inside binders:
- ///
- /// ```
- /// for<'a> fn(for<'b> for<'c> fn(&'a u32), _)
- /// // Binder: D3 D2 D1 ^^
- /// ```
- ///
- /// Here, the region `'a` would have the De Bruijn index D3,
- /// because it is the bound 3 binders out. However, if we wanted
- /// to refer to that region `'a` in the second argument (the `_`),
- /// those two binders would not be in scope. In that case, we
- /// might invoke `shift_out_to_binder(D3)`. This would adjust the
- /// De Bruijn index of `'a` to D1 (the innermost binder).
- ///
- /// If we invoke `shift_out_to_binder` and the region is in fact
- /// bound by one of the binders we are shifting out of, that is an
- /// error (and should fail an assertion failure).
- pub fn shifted_out_to_binder(&self, to_binder: ty::DebruijnIndex) -> RegionKind {
- match *self {
- ty::ReLateBound(debruijn, r) => {
- ty::ReLateBound(debruijn.shifted_out_to_binder(to_binder), r)
- }
- r => r,
- }
- }
-
pub fn type_flags(&self) -> TypeFlags {
let mut flags = TypeFlags::empty();