pub fn trait_method<'a>(ccx: &CrateContext<'a, 'tcx>,
                            trait_id: DefId,
                            def_id: DefId,
                            substs: &'tcx Substs<'tcx>)
                            -> Callee<'tcx> {
        let tcx = ccx.tcx();

        let trait_ref = ty::TraitRef::from_method(tcx, trait_id, substs);
        let trait_ref = tcx.normalize_associated_type(&ty::Binder(trait_ref));
        match common::fulfill_obligation(ccx.shared(), DUMMY_SP, trait_ref) {
            traits::VtableImpl(vtable_impl) => {
                let name = tcx.item_name(def_id);
                let (def_id, substs) = traits::find_method(tcx, name, substs, &vtable_impl);

                // Translate the function, bypassing Callee::def.
                // That is because default methods have the same ID as the
                // trait method used to look up the impl method that ended
                // up here, so calling Callee::def would infinitely recurse.
                let (llfn, ty) = get_fn(ccx, def_id, substs);
                Callee::ptr(llfn, ty)
            }
            traits::VtableClosure(vtable_closure) => {
                // The substitutions should have no type parameters remaining
                // after passing through fulfill_obligation
                let trait_closure_kind = tcx.lang_items.fn_trait_kind(trait_id).unwrap();
                let instance = Instance::new(def_id, substs);
                let llfn = trans_closure_method(
                    ccx,
                    vtable_closure.closure_def_id,
                    vtable_closure.substs,
                    instance,
                    trait_closure_kind);

                let method_ty = def_ty(ccx.shared(), def_id, substs);
                Callee::ptr(llfn, method_ty)
            }
            traits::VtableFnPointer(vtable_fn_pointer) => {
                let trait_closure_kind = tcx.lang_items.fn_trait_kind(trait_id).unwrap();
                let instance = Instance::new(def_id, substs);
                let llfn = trans_fn_pointer_shim(ccx, instance,
                                                 trait_closure_kind,
                                                 vtable_fn_pointer.fn_ty);

                let method_ty = def_ty(ccx.shared(), def_id, substs);
                Callee::ptr(llfn, method_ty)
            }
            traits::VtableObject(ref data) => {
                Callee {
                    data: Virtual(tcx.get_vtable_index_of_object_method(data, def_id)),
                    ty: def_ty(ccx.shared(), def_id, substs)
                }
            }
            vtable => {
                bug!("resolved vtable bad vtable {:?} in trans", vtable);
            }
        }
    }
/// Trait method, which has to be resolved to an impl method.
Trait method, which has to be resolved to an impl method.
Trait method which has to be resolved to an impl method .
pub fn trait_method<'a>(ccx: &CrateContext<'a, 'tcx>,
                            trait_id: DefId,
                            def_id: DefId,
                            substs: &'tcx Substs<'tcx>)
                            -> Callee<'tcx> {
        let tcx = ccx.tcx();
        let trait_ref = ty::TraitRef::from_method(tcx, trait_id, substs);
        let trait_ref = tcx.normalize_associated_type(&ty::Binder(trait_ref));
        match common::fulfill_obligation(ccx.shared(), DUMMY_SP, trait_ref) {
            traits::VtableImpl(vtable_impl) => {
                let name = tcx.item_name(def_id);
                let (def_id, substs) = traits::find_method(tcx, name, substs, &vtable_impl);
                // Translate the function, bypassing Callee::def.
                // That is because default methods have the same ID as the
                // trait method used to look up the impl method that ended
                // up here, so calling Callee::def would infinitely recurse.
                let (llfn, ty) = get_fn(ccx, def_id, substs);
                Callee::ptr(llfn, ty)
            }
            traits::VtableClosure(vtable_closure) => {
                // The substitutions should have no type parameters remaining
                // after passing through fulfill_obligation
                let trait_closure_kind = tcx.lang_items.fn_trait_kind(trait_id).unwrap();
                let instance = Instance::new(def_id, substs);
                let llfn = trans_closure_method(
                    ccx,
                    vtable_closure.closure_def_id,
                    vtable_closure.substs,
                    instance,
                    trait_closure_kind);
                let method_ty = def_ty(ccx.shared(), def_id, substs);
                Callee::ptr(llfn, method_ty)
            }
            traits::VtableFnPointer(vtable_fn_pointer) => {
                let trait_closure_kind = tcx.lang_items.fn_trait_kind(trait_id).unwrap();
                let instance = Instance::new(def_id, substs);
                let llfn = trans_fn_pointer_shim(ccx, instance,
                                                 trait_closure_kind,
                                                 vtable_fn_pointer.fn_ty);
                let method_ty = def_ty(ccx.shared(), def_id, substs);
                Callee::ptr(llfn, method_ty)
            }
            traits::VtableObject(ref data) => {
                Callee {
                    data: Virtual(tcx.get_vtable_index_of_object_method(data, def_id)),
                    ty: def_ty(ccx.shared(), def_id, substs)
                }
            }
            vtable => {
                bug!("resolved vtable bad vtable {:?} in trans", vtable);
            }
        }
    }
pub fn trait_method < ' a > ( ccx : & CrateContext < ' a , ' tcx > , trait_id : DefId , def_id : DefId , substs : & ' tcx Substs < ' tcx > ) -> Callee < ' tcx > { let tcx = ccx . tcx ( ) ; let trait_ref = ty :: TraitRef :: from_method ( tcx , trait_id , substs ) ; let trait_ref = tcx . normalize_associated_type ( & ty :: Binder ( trait_ref ) ) ; match common :: fulfill_obligation ( ccx . shared ( ) , DUMMY_SP , trait_ref ) { traits :: VtableImpl ( vtable_impl ) => { let name = tcx . item_name ( def_id ) ; let ( def_id , substs ) = traits :: find_method ( tcx , name , substs , & vtable_impl ) ; // Translate the function, bypassing Callee::def. // That is because default methods have the same ID as the // trait method used to look up the impl method that ended // up here, so calling Callee::def would infinitely recurse. let ( llfn , ty ) = get_fn ( ccx , def_id , substs ) ; Callee :: ptr ( llfn , ty ) } traits :: VtableClosure ( vtable_closure ) => { // The substitutions should have no type parameters remaining // after passing through fulfill_obligation let trait_closure_kind = tcx . lang_items . fn_trait_kind ( trait_id ) . unwrap ( ) ; let instance = Instance :: new ( def_id , substs ) ; let llfn = trans_closure_method ( ccx , vtable_closure . closure_def_id , vtable_closure . substs , instance , trait_closure_kind ) ; let method_ty = def_ty ( ccx . shared ( ) , def_id , substs ) ; Callee :: ptr ( llfn , method_ty ) } traits :: VtableFnPointer ( vtable_fn_pointer ) => { let trait_closure_kind = tcx . lang_items . fn_trait_kind ( trait_id ) . unwrap ( ) ; let instance = Instance :: new ( def_id , substs ) ; let llfn = trans_fn_pointer_shim ( ccx , instance , trait_closure_kind , vtable_fn_pointer . fn_ty ) ; let method_ty = def_ty ( ccx . shared ( ) , def_id , substs ) ; Callee :: ptr ( llfn , method_ty ) } traits :: VtableObject ( ref data ) => { Callee { data : Virtual ( tcx . get_vtable_index_of_object_method ( data , def_id ) ) , ty : def_ty ( ccx . shared ( ) , def_id , substs ) } } vtable => { bug ! ( " " vtable ) ; } } }
Trait method, which has to be resolved to an impl method.
Trait method which has to be resolved to an impl method .
ccx
&CrateContext<'a, 'tcx>
trait_id
DefId
def_id
DefId
substs
&'tcx Substs<'tcx>
ccx
&CrateContext<'a, 'tcx>
trait_id
DefId
def_id
DefId
substs
&'tcx Substs<'tcx>