@@ -64,9 +64,35 @@ pub fn translate_substs<'tcx>(tcx: &ty::ctxt<'tcx>,
64
64
/// When we have selected one impl, but are actually using item definitions from
65
65
/// a parent impl providing a default, we need a way to translate between the
66
66
/// type parameters of the two impls. Here the `source_impl` is the one we've
67
- /// selected, and `source_substs` is a substitution of its generics (and possibly
68
- /// some relevant `FnSpace` variables as well). And `target_impl` is the impl
69
- /// we're actually going to get the definition from.
67
+ /// selected, and `source_substs` is a substitution of its generics (and
68
+ /// possibly some relevant `FnSpace` variables as well). And `target_impl` is
69
+ /// the impl we're actually going to get the definition from. The resulting
70
+ /// substitution will map from `target_impl`'s generics to `source_impl`'s
71
+ /// generics as instantiated by `source_subst`.
72
+ ///
73
+ /// For example, consider the following scenario:
74
+ ///
75
+ /// ```rust
76
+ /// trait Foo { ... }
77
+ /// impl<T, U> Foo for (T, U) { ... } // target impl
78
+ /// impl<V> Foo for (V, V) { ... } // source impl
79
+ /// ```
80
+ ///
81
+ /// Suppose we have selected "source impl" with `V` instantiated with `u32`.
82
+ /// This function will produce a substitution with `T` and `U` both mapping to `u32`.
83
+ ///
84
+ /// Where clauses add some trickiness here, because they can be used to "define"
85
+ /// an argument indirectly:
86
+ ///
87
+ /// ```rust
88
+ /// impl<'a, I, T: 'a> Iterator for Cloned<I>
89
+ /// where I: Iterator<Item=&'a T>, T: Clone
90
+ /// ```
91
+ ///
92
+ /// In a case like this, the substitution for `T` is determined indirectly,
93
+ /// through associated type projection. We deal with such cases by using
94
+ /// *fulfillment* to relate the two impls, requiring that all projections are
95
+ /// resolved.
70
96
fn translate_substs_between_impls < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
71
97
source_impl : DefId ,
72
98
source_substs : Substs < ' tcx > ,
0 commit comments