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

pub enum Vtable<'tcx, N> {
    VtableImpl(VtableImplData<'tcx, N>),
    VtableDefaultImpl(VtableDefaultImplData<N>),
    VtableParam(Vec<N>),
    VtableObject(VtableObjectData<'tcx>),
    VtableBuiltin(VtableBuiltinData<N>),
    VtableClosure(DefId, Substs<'tcx>),
    VtableFnPointer(&'tcx TyS<'tcx>),
}

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

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

The type parameter N

See explanation on VtableImplData.

Variants

VtableImpl

Vtable identifying a particular impl.

VtableDefaultImpl

Vtable for default trait implementations This carries the information and nested obligations with regards to a default implementation for a trait Trait. The nested obligations ensure the trait implementation holds for all the constituent types.

VtableParam

Successful resolution to an obligation provided by the caller for some type parameter. The Vec<N> represents the obligations incurred from normalizing the where-clause (if any).

VtableObject

Virtual calls through an object

VtableBuiltin

Successful resolution for a builtin trait.

VtableClosure

Vtable automatically generated for a 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.

VtableFnPointer

Same as above, but for a fn pointer type with the given signature.

Methods

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

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

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

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

Trait Implementations

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

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

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

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

Derived Implementations

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

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

fn clone_from(&mut self, source: &Self)

impl<'tcx, N> Debug for Vtable<'tcx, N> where N: Debug + Debug + Debug + Debug + Debug

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