@@ -85,6 +85,37 @@ impl<'a, 'gcx, 'tcx> Deref for ProbeContext<'a, 'gcx, 'tcx> {
85
85
86
86
#[ derive( Debug ) ]
87
87
struct Candidate < ' tcx > {
88
+ // Candidates are (I'm not quite sure, but they are mostly) basically
89
+ // some metadata on top of a `ty::AssociatedItem` (without substs).
90
+ //
91
+ // However, method probing wants to be able to evaluate the predicates
92
+ // for a function with the substs applied - for example, if a function
93
+ // has `where Self: Sized`, we don't want to consider it unless `Self`
94
+ // is actually `Sized`, and similarly, return-type suggestions want
95
+ // to consider the "actual" return type.
96
+ //
97
+ // The way this is handled is through `xform_self_ty`. It contains
98
+ // the receiver type of this candidate, but `xform_self_ty`,
99
+ // `xform_ret_ty` and `kind` (which contains the predicates) have the
100
+ // generic parameters of this candidate substituted with the *same set*
101
+ // of inference variables, which acts as some weird sort of "query".
102
+ //
103
+ // When we check out a candidate, we require `xform_self_ty` to be
104
+ // a subtype of the passed-in self-type, and this equates the type
105
+ // variables in the rest of the fields.
106
+ //
107
+ // For example, if we have this candidate:
108
+ // ```
109
+ // trait Foo {
110
+ // fn foo(&self) where Self: Sized;
111
+ // }
112
+ // ```
113
+ //
114
+ // Then `xform_self_ty` will be `&'erased ?X` and `kind` will contain
115
+ // the predicate `?X: Sized`, so if we are evaluating `Foo` for a
116
+ // the receiver `&T`, we'll do the subtyping which will make `?X`
117
+ // get the right value, then when we evaluate the predicate we'll check
118
+ // if `T: Sized`.
88
119
xform_self_ty : Ty < ' tcx > ,
89
120
xform_ret_ty : Option < Ty < ' tcx > > ,
90
121
item : ty:: AssociatedItem ,
0 commit comments