- // Load the info for the appropriate trait if necessary.
- match tcx.trait_of_item(def_id) {
- None => {}
- Some(trait_id) => {
- tcx.populate_implementations_for_trait_if_necessary(trait_id)
- }
- }
-
- // We need to do a bunch of special handling for default methods.
- // We need to modify the def_id and our substs in order to monomorphize
- // the function.
- let (is_default, def_id, substs) = match tcx.provided_source(def_id) {
- None => {
- (false, def_id, tcx.mk_substs(substs))
- }
- Some(source_id) => {
- // There are two relevant substitutions when compiling
- // default methods. First, there is the substitution for
- // the type parameters of the impl we are using and the
- // method we are calling. This substitution is the substs
- // argument we already have.
- // In order to compile a default method, though, we need
- // to consider another substitution: the substitution for
- // the type parameters on trait; the impl we are using
- // implements the trait at some particular type
- // parameters, and we need to substitute for those first.
- // So, what we need to do is find this substitution and
- // compose it with the one we already have.
-
- let impl_id = tcx.impl_or_trait_item(def_id).container()
- .id();
- let impl_or_trait_item = tcx.impl_or_trait_item(source_id);
- match impl_or_trait_item {
- ty::MethodTraitItem(method) => {
- let trait_ref = tcx.impl_trait_ref(impl_id).unwrap();
-
- // Compute the first substitution
- let first_subst =
- tcx.make_substs_for_receiver_types(&trait_ref, &*method)
- .erase_regions();
-
- // And compose them
- let new_substs = tcx.mk_substs(first_subst.subst(tcx, &substs));
-
- debug!("trans_fn_with_vtables - default method: \
- substs = {:?}, trait_subst = {:?}, \
- first_subst = {:?}, new_subst = {:?}",
- substs, trait_ref.substs,
- first_subst, new_substs);
-
- (true, source_id, new_substs)
- }
- _ => {
- tcx.sess.bug("trans_fn_ref_with_vtables() tried \
- to translate a non-method?!")
- }
- }
- }
- };
-