// Given a trait-method and substitution information, find out the actual
// implementation of the trait method.
Given a trait-method and substitution information, find out the actual
implementation of the trait method.
Given a trait - method and substitution information find out the actual implementation of the trait method .
fn do_static_trait_method_dispatch<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
                                             trait_method: &ty::Method,
                                             trait_id: DefId,
                                             callee_substs: &'tcx Substs<'tcx>,
                                             param_substs: &'tcx Substs<'tcx>)
                                             -> Option<(DefId, &'tcx Substs<'tcx>)> {
    let tcx = scx.tcx();
    debug!("do_static_trait_method_dispatch(trait_method={}, \
                                            trait_id={}, \
                                            callee_substs={:?}, \
                                            param_substs={:?}",
           def_id_to_string(scx.tcx(), trait_method.def_id),
           def_id_to_string(scx.tcx(), trait_id),
           callee_substs,
           param_substs);
    let rcvr_substs = monomorphize::apply_param_substs(tcx,
                                                       param_substs,
                                                       &callee_substs);
    let trait_ref = ty::Binder(rcvr_substs.to_trait_ref(tcx, trait_id));
    let trait_ref = tcx.normalize_associated_type(&trait_ref);
    let vtbl = fulfill_obligation(scx, DUMMY_SP, trait_ref);
    // Now that we know which impl is being used, we can dispatch to
    // the actual function:
    match vtbl {
        traits::VtableImpl(traits::VtableImplData {
            impl_def_id: impl_did,
            substs: impl_substs,
            nested: _ }) =>
        {
            let callee_substs = impl_substs.with_method_from(&rcvr_substs);
            let impl_method = meth::get_impl_method(tcx,
                                                    impl_did,
                                                    tcx.mk_substs(callee_substs),
                                                    trait_method.name);
            Some((impl_method.method.def_id, &impl_method.substs))
        }
        // If we have a closure or a function pointer, we will also encounter
        // the concrete closure/function somewhere else (during closure or fn
        // pointer construction). That's where we track those things.
        traits::VtableClosure(..) |
        traits::VtableFnPointer(..) |
        traits::VtableObject(..) => {
            None
        }
        _ => {
            bug!("static call to invalid vtable: {:?}", vtbl)
        }
    }
}
fn do_static_trait_method_dispatch < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > , trait_method : & ty :: Method , trait_id : DefId , callee_substs : & ' tcx Substs < ' tcx > , param_substs : & ' tcx Substs < ' tcx > ) -> Option < ( DefId , & ' tcx Substs < ' tcx > ) > { let tcx = scx . tcx ( ) ; debug ! ( " \
 \
 \
 " def_id_to_string ( scx tcx ( ) trait_method def_id ) def_id_to_string ( scx tcx ( ) trait_id ) callee_substs param_substs ) ; let rcvr_substs = monomorphize :: apply_param_substs ( tcx , param_substs , & callee_substs ) ; let trait_ref = ty :: Binder ( rcvr_substs . to_trait_ref ( tcx , trait_id ) ) ; let trait_ref = tcx . normalize_associated_type ( & trait_ref ) ; let vtbl = fulfill_obligation ( scx , DUMMY_SP , trait_ref ) ; // Now that we know which impl is being used, we can dispatch to // the actual function: match vtbl { traits :: VtableImpl ( traits :: VtableImplData { impl_def_id : impl_did , substs : impl_substs , nested : _ } ) => { let callee_substs = impl_substs . with_method_from ( & rcvr_substs ) ; let impl_method = meth :: get_impl_method ( tcx , impl_did , tcx . mk_substs ( callee_substs ) , trait_method . name ) ; Some ( ( impl_method . method . def_id , & impl_method . substs ) ) } // If we have a closure or a function pointer, we will also encounter // the concrete closure/function somewhere else (during closure or fn // pointer construction). That's where we track those things. traits :: VtableClosure ( .. ) | traits :: VtableFnPointer ( .. ) | traits :: VtableObject ( .. ) => { None } _ => { bug ! ( " " vtbl ) } } }
Given a trait-method and substitution information, find out the actual
implementation of the trait method.
Given a trait - method and substitution information find out the actual implementation of the trait method .
scx
&SharedCrateContext<'a, 'tcx>
trait_method
&ty::Method
trait_id
DefId
callee_substs
&'tcx Substs<'tcx>
param_substs
&'tcx Substs<'tcx>