/// Given a subst for the requested impl, translate it to a subst
/// appropriate for the actual item definition (whether it be in that impl,
/// a parent impl, or the trait).
/// When we have selected one impl, but are actually using item definitions from
/// a parent impl providing a default, we need a way to translate between the
/// type parameters of the two impls. Here the `source_impl` is the one we've
/// selected, and `source_substs` is a substitution of its generics (and
/// possibly some relevant `FnSpace` variables as well). And `target_node` is
/// the impl/trait we're actually going to get the definition from. The resulting
/// substitution will map from `target_node`'s generics to `source_impl`'s
/// generics as instantiated by `source_subst`.
///
/// For example, consider the following scenario:
///
/// ```rust
/// trait Foo { ... }
/// impl<T, U> Foo for (T, U) { ... }  // target impl
/// impl<V> Foo for (V, V) { ... }     // source impl
/// ```
///
/// Suppose we have selected "source impl" with `V` instantiated with `u32`.
/// This function will produce a substitution with `T` and `U` both mapping to `u32`.
///
/// Where clauses add some trickiness here, because they can be used to "define"
/// an argument indirectly:
///
/// ```rust
/// impl<'a, I, T: 'a> Iterator for Cloned<I>
///    where I: Iterator<Item=&'a T>, T: Clone
/// ```
///
/// In a case like this, the substitution for `T` is determined indirectly,
/// through associated type projection. We deal with such cases by using
/// *fulfillment* to relate the two impls, requiring that all projections are
/// resolved.
Given a subst for the requested impl, translate it to a subst
appropriate for the actual item definition (whether it be in that impl,
a parent impl, or the trait).
When we have selected one impl, but are actually using item definitions from
a parent impl providing a default, we need a way to translate between the
type parameters of the two impls.

For example, consider the following scenario.

```rust
trait Foo { ...

Suppose we have selected "source impl" with `V` instantiated with `u32`.





In a case like this, the substitution for `T` is determined indirectly,
through associated type projection. We deal with such cases by using
fulfillment* to relate the two impls, requiring that all projections are
resolved.
Given a subst for the requested impl translate it to a subst appropriate for the actual item definition ( whether it be in that impl a parent impl or the trait ) . When we have selected one impl but are actually using item definitions from a parent impl providing a default we need a way to translate between the type parameters of the two impls . For example consider the following scenario . ` ` ` rust trait Foo { ... Suppose we have selected " source impl " with ` V ` instantiated with ` u32 ` . In a case like this the substitution for ` T ` is determined indirectly through associated type projection . We deal with such cases by using fulfillment * to relate the two impls requiring that all projections are resolved .
pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
                                        source_impl: DefId,
                                        source_substs: &'tcx Substs<'tcx>,
                                        target_node: specialization_graph::Node)
                                        -> &'tcx Substs<'tcx> {
    let source_trait_ref = infcx.tcx
                                .impl_trait_ref(source_impl)
                                .unwrap()
                                .subst(infcx.tcx, &source_substs);
    // translate the Self and TyParam parts of the substitution, since those
    // vary across impls
    let target_substs = match target_node {
        specialization_graph::Node::Impl(target_impl) => {
            // no need to translate if we're targetting the impl we started with
            if source_impl == target_impl {
                return source_substs;
            }
            fulfill_implication(infcx, source_trait_ref, target_impl).unwrap_or_else(|_| {
                bug!("When translating substitutions for specialization, the expected \
                      specializaiton failed to hold")
            })
        }
        specialization_graph::Node::Trait(..) => source_trait_ref.substs,
    };
    // directly inherent the method generics, since those do not vary across impls
    infcx.tcx.mk_substs(target_substs.with_method_from_subst(source_substs))
}
pub fn translate_substs < ' a , ' gcx , ' tcx > ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > , source_impl : DefId , source_substs : & ' tcx Substs < ' tcx > , target_node : specialization_graph :: Node ) -> & ' tcx Substs < ' tcx > { let source_trait_ref = infcx . tcx . impl_trait_ref ( source_impl ) . unwrap ( ) . subst ( infcx . tcx , & source_substs ) ; // translate the Self and TyParam parts of the substitution, since those // vary across impls let target_substs = match target_node { specialization_graph :: Node :: Impl ( target_impl ) => { // no need to translate if we're targetting the impl we started with if source_impl == target_impl { return source_substs ; } fulfill_implication ( infcx , source_trait_ref , target_impl ) . unwrap_or_else ( | _ | { bug ! ( " \
 " ) } ) } specialization_graph :: Node :: Trait ( .. ) => source_trait_ref . substs , } ; // directly inherent the method generics, since those do not vary across impls infcx . tcx . mk_substs ( target_substs . with_method_from_subst ( source_substs ) ) }
Given a subst for the requested impl, translate it to a subst
appropriate for the actual item definition (whether it be in that impl,
a parent impl, or the trait).
Given a subst for the requested impl translate it to a subst appropriate for the actual item definition ( whether it be in that impl a parent impl or the trait ) .
infcx
&InferCtxt<'a, 'gcx, 'tcx>
source_impl
DefId
source_substs
&'tcx Substs<'tcx>
target_node
specialization_graph::Node