@@ -205,6 +205,7 @@ impl<'a> InferenceContext<'a> {
205
205
Some ( ( def, Some ( trait_ref. substitution ) ) )
206
206
}
207
207
208
+ // FIXME: Change sig to -> Option<(ValueNs, Substitution)>, subs aren't optional from here anymore
208
209
fn resolve_ty_assoc_item (
209
210
& mut self ,
210
211
ty : Ty ,
@@ -220,70 +221,66 @@ impl<'a> InferenceContext<'a> {
220
221
}
221
222
222
223
let canonical_ty = self . canonicalize ( ty. clone ( ) ) ;
223
- let traits_in_scope = self . resolver . traits_in_scope ( self . db . upcast ( ) ) ;
224
224
225
225
let mut not_visible = None ;
226
226
let res = method_resolution:: iterate_method_candidates (
227
227
& canonical_ty. value ,
228
228
self . db ,
229
229
self . table . trait_env . clone ( ) ,
230
- & traits_in_scope ,
230
+ self . get_traits_in_scope ( ) . as_ref ( ) . left_or_else ( | & it| it ) ,
231
231
VisibleFromModule :: Filter ( self . resolver . module ( ) ) ,
232
232
Some ( name) ,
233
233
method_resolution:: LookupMode :: Path ,
234
234
|_ty, item, visible| {
235
- let ( def, container) = match item {
236
- AssocItemId :: FunctionId ( f) => {
237
- ( ValueNs :: FunctionId ( f) , f. lookup ( self . db . upcast ( ) ) . container )
238
- }
239
- AssocItemId :: ConstId ( c) => {
240
- ( ValueNs :: ConstId ( c) , c. lookup ( self . db . upcast ( ) ) . container )
241
- }
242
- AssocItemId :: TypeAliasId ( _) => unreachable ! ( ) ,
243
- } ;
244
- let substs = match container {
245
- ItemContainerId :: ImplId ( impl_id) => {
246
- let impl_substs = TyBuilder :: subst_for_def ( self . db , impl_id, None )
247
- . fill_with_inference_vars ( & mut self . table )
248
- . build ( ) ;
249
- let impl_self_ty =
250
- self . db . impl_self_ty ( impl_id) . substitute ( Interner , & impl_substs) ;
251
- self . unify ( & impl_self_ty, & ty) ;
252
- impl_substs
253
- }
254
- ItemContainerId :: TraitId ( trait_) => {
255
- // we're picking this method
256
- let trait_ref = TyBuilder :: trait_ref ( self . db , trait_)
257
- . push ( ty. clone ( ) )
258
- . fill_with_inference_vars ( & mut self . table )
259
- . build ( ) ;
260
- self . push_obligation ( trait_ref. clone ( ) . cast ( Interner ) ) ;
261
- trait_ref. substitution
262
- }
263
- ItemContainerId :: ModuleId ( _) | ItemContainerId :: ExternBlockId ( _) => {
264
- never ! ( "assoc item contained in module/extern block" ) ;
265
- return None ;
266
- }
267
- } ;
268
-
269
235
if visible {
270
- Some ( ( def , item, Some ( substs ) , true ) )
236
+ Some ( ( item, true ) )
271
237
} else {
272
238
if not_visible. is_none ( ) {
273
- not_visible = Some ( ( def , item, Some ( substs ) , false ) ) ;
239
+ not_visible = Some ( ( item, false ) ) ;
274
240
}
275
241
None
276
242
}
277
243
} ,
278
244
) ;
279
245
let res = res. or ( not_visible) ;
280
- if let Some ( ( _, item, Some ( ref substs) , visible) ) = res {
281
- self . write_assoc_resolution ( id, item, substs. clone ( ) ) ;
282
- if !visible {
283
- self . push_diagnostic ( InferenceDiagnostic :: PrivateAssocItem { id, item } )
246
+ let ( item, visible) = res?;
247
+
248
+ let ( def, container) = match item {
249
+ AssocItemId :: FunctionId ( f) => {
250
+ ( ValueNs :: FunctionId ( f) , f. lookup ( self . db . upcast ( ) ) . container )
284
251
}
252
+ AssocItemId :: ConstId ( c) => ( ValueNs :: ConstId ( c) , c. lookup ( self . db . upcast ( ) ) . container ) ,
253
+ AssocItemId :: TypeAliasId ( _) => unreachable ! ( ) ,
254
+ } ;
255
+ let substs = match container {
256
+ ItemContainerId :: ImplId ( impl_id) => {
257
+ let impl_substs = TyBuilder :: subst_for_def ( self . db , impl_id, None )
258
+ . fill_with_inference_vars ( & mut self . table )
259
+ . build ( ) ;
260
+ let impl_self_ty = self . db . impl_self_ty ( impl_id) . substitute ( Interner , & impl_substs) ;
261
+ self . unify ( & impl_self_ty, & ty) ;
262
+ impl_substs
263
+ }
264
+ ItemContainerId :: TraitId ( trait_) => {
265
+ // we're picking this method
266
+ let trait_ref = TyBuilder :: trait_ref ( self . db , trait_)
267
+ . push ( ty. clone ( ) )
268
+ . fill_with_inference_vars ( & mut self . table )
269
+ . build ( ) ;
270
+ self . push_obligation ( trait_ref. clone ( ) . cast ( Interner ) ) ;
271
+ trait_ref. substitution
272
+ }
273
+ ItemContainerId :: ModuleId ( _) | ItemContainerId :: ExternBlockId ( _) => {
274
+ never ! ( "assoc item contained in module/extern block" ) ;
275
+ return None ;
276
+ }
277
+ } ;
278
+
279
+ self . write_assoc_resolution ( id, item, substs. clone ( ) ) ;
280
+ if !visible {
281
+ self . push_diagnostic ( InferenceDiagnostic :: PrivateAssocItem { id, item } ) ;
285
282
}
286
- res . map ( | ( def, _ , substs , _ ) | ( def , substs) )
283
+ Some ( ( def, Some ( substs) ) )
287
284
}
288
285
289
286
fn resolve_enum_variant_on_ty (
0 commit comments