Skip to content

Commit 141e97b

Browse files
committed
---
yaml --- r: 273155 b: refs/heads/beta c: 8f20cbf h: refs/heads/master i: 273153: 352d186 273151: 2e9fba5
1 parent e9188f8 commit 141e97b

File tree

2 files changed

+30
-4
lines changed
  • branches/beta/src/librustc/middle/traits/specialize

2 files changed

+30
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 940adda2aef63ac820cf331ebb7f6f0699c12045
26+
refs/heads/beta: 8f20cbf03088c8fa89a343de9e97e7608cd701b6
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/middle/traits/specialize/mod.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,35 @@ pub fn translate_substs<'tcx>(tcx: &ty::ctxt<'tcx>,
6464
/// When we have selected one impl, but are actually using item definitions from
6565
/// a parent impl providing a default, we need a way to translate between the
6666
/// 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.
7096
fn translate_substs_between_impls<'tcx>(tcx: &ty::ctxt<'tcx>,
7197
source_impl: DefId,
7298
source_substs: Substs<'tcx>,

0 commit comments

Comments
 (0)