Enum rustc_trans::middle::traits::VtableExperimental [-]  [+] [src]

pub enum Vtable<'tcx, N> {
    VtableImpl(VtableImplData<'tcx, N>),
    VtableUnboxedClosure(DefId, Substs<'tcx>),
    VtableParam(VtableParamData<'tcx>),
    VtableBuiltin(VtableBuiltinData<N>),
}

Given the successful resolution of an obligation, the Vtable indicates where the vtable comes from. Note that while we call this a "vtable", it does not necessarily indicate dynamic dispatch at runtime. Vtable instances just tell the compiler where to find methods, but in generic code those methods are typically statically dispatched -- only when an object is constructed is a Vtable instance reified into an actual vtable.

For example, the vtable may be tied to a specific impl (case A), or it may be relative to some bound that is in scope (case B).

impl<T:Clone> Clone<T> for Option<T> { ... } // Impl_1
impl<T:Clone> Clone<T> for Box<T> { ... }    // Impl_2
impl Clone for int { ... }             // Impl_3

fn foo<T:Clone>(concrete: Option<Box<int>>,
                param: T,
                mixed: Option<T>) {

   // Case A: Vtable points at a specific impl. Only possible when
   // type is concretely known. If the impl itself has bounded
   // type parameters, Vtable will carry resolutions for those as well:
   concrete.clone(); // Vtable(Impl_1, [Vtable(Impl_2, [Vtable(Impl_3)])])

   // Case B: Vtable must be provided by caller. This applies when
   // type is a type parameter.
   param.clone();    // VtableParam(Oblig_1)

   // Case C: A mix of cases A and B.
   mixed.clone();    // Vtable(Impl_1, [VtableParam(Oblig_1)])
}

The type parameter N

See explanation on VtableImplData.

Variants

VtableImpl

Vtable identifying a particular impl.

VtableUnboxedClosure

Vtable automatically generated for an unboxed closure. The def ID is the ID of the closure expression. This is a VtableImpl in spirit, but the impl is generated by the compiler and does not appear in the source.

VtableParam

Successful resolution to an obligation provided by the caller for some type parameter.

VtableBuiltin

Successful resolution for a builtin trait.

Methods

impl<'tcx, N> Vtable<'tcx, N>

fn iter_nested(&self) -> Items<N>

fn map_nested<M>(&self, op: |&N| -> M) -> Vtable<'tcx, M>

fn map_move_nested<M>(self, op: |N| -> M) -> Vtable<'tcx, M>

Trait Implementations

impl<'tcx, N: Repr<'tcx>> Repr<'tcx> for Vtable<'tcx, N>

fn repr(&self, tcx: &ctxt<'tcx>) -> String

impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vtable<'tcx, N>

fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Vtable<'tcx, N>

Derived Implementations

impl<'tcx, N: Clone> Clone for Vtable<'tcx, N>

fn clone(&self) -> Vtable<'tcx, N>

fn clone_from(&mut self, &Vtable<'tcx, N>)

impl<'tcx, N: Show> Show for Vtable<'tcx, N>

fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>