@@ -106,7 +106,7 @@ enum CandidateKind<'tcx> {
106
106
ty:: PolyTraitRef < ' tcx > ) ,
107
107
}
108
108
109
- #[ derive( Debug ) ]
109
+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
110
110
pub struct Pick < ' tcx > {
111
111
pub item : ty:: AssociatedItem ,
112
112
pub kind : PickKind < ' tcx > ,
@@ -130,7 +130,7 @@ pub struct Pick<'tcx> {
130
130
pub unsize : Option < Ty < ' tcx > > ,
131
131
}
132
132
133
- #[ derive( Clone , Debug ) ]
133
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
134
134
pub enum PickKind < ' tcx > {
135
135
InherentImplPick ,
136
136
ExtensionImplPick ( // Impl
@@ -155,6 +155,15 @@ pub enum Mode {
155
155
Path ,
156
156
}
157
157
158
+ #[ derive( PartialEq , Eq , Copy , Clone , Debug ) ]
159
+ pub enum ProbeScope {
160
+ // Assemble candidates coming only from traits in scope.
161
+ TraitsInScope ,
162
+
163
+ // Assemble candidates coming from all traits.
164
+ AllTraits ,
165
+ }
166
+
158
167
impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
159
168
/// This is used to offer suggestions to users. It returns methods
160
169
/// that could have been called which have the desired return
@@ -175,14 +184,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
175
184
scope_expr_id) ;
176
185
let method_names =
177
186
self . probe_op ( span, mode, LookingFor :: ReturnType ( return_type) , IsSuggestion ( true ) ,
178
- self_ty, scope_expr_id,
187
+ self_ty, scope_expr_id, ProbeScope :: TraitsInScope ,
179
188
|probe_cx| Ok ( probe_cx. candidate_method_names ( ) ) )
180
189
. unwrap_or ( vec ! [ ] ) ;
181
190
method_names
182
191
. iter ( )
183
192
. flat_map ( |& method_name| {
184
193
match self . probe_for_name ( span, mode, method_name, IsSuggestion ( true ) , self_ty,
185
- scope_expr_id) {
194
+ scope_expr_id, ProbeScope :: TraitsInScope ) {
186
195
Ok ( pick) => Some ( pick. item ) ,
187
196
Err ( _) => None ,
188
197
}
@@ -196,7 +205,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
196
205
item_name : ast:: Name ,
197
206
is_suggestion : IsSuggestion ,
198
207
self_ty : Ty < ' tcx > ,
199
- scope_expr_id : ast:: NodeId )
208
+ scope_expr_id : ast:: NodeId ,
209
+ scope : ProbeScope )
200
210
-> PickResult < ' tcx > {
201
211
debug ! ( "probe(self_ty={:?}, item_name={}, scope_expr_id={})" ,
202
212
self_ty,
@@ -208,6 +218,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
208
218
is_suggestion,
209
219
self_ty,
210
220
scope_expr_id,
221
+ scope,
211
222
|probe_cx| probe_cx. pick ( ) )
212
223
}
213
224
@@ -218,6 +229,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
218
229
is_suggestion : IsSuggestion ,
219
230
self_ty : Ty < ' tcx > ,
220
231
scope_expr_id : ast:: NodeId ,
232
+ scope : ProbeScope ,
221
233
op : OP )
222
234
-> Result < R , MethodError < ' tcx > >
223
235
where OP : FnOnce ( ProbeContext < ' a , ' gcx , ' tcx > ) -> Result < R , MethodError < ' tcx > >
@@ -275,8 +287,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
275
287
let mut probe_cx =
276
288
ProbeContext :: new ( self , span, mode, looking_for,
277
289
steps, opt_simplified_steps) ;
290
+
278
291
probe_cx. assemble_inherent_candidates ( ) ;
279
- probe_cx. assemble_extension_candidates_for_traits_in_scope ( scope_expr_id) ?;
292
+ match scope {
293
+ ProbeScope :: TraitsInScope =>
294
+ probe_cx. assemble_extension_candidates_for_traits_in_scope ( scope_expr_id) ?,
295
+ ProbeScope :: AllTraits =>
296
+ probe_cx. assemble_extension_candidates_for_all_traits ( ) ?,
297
+ } ;
280
298
op ( probe_cx)
281
299
} )
282
300
}
0 commit comments