@@ -205,6 +205,7 @@ impl<'a> InferenceContext<'a> {
205205 Some ( ( def, Some ( trait_ref. substitution ) ) )
206206 }
207207
208+ // FIXME: Change sig to -> Option<(ValueNs, Substitution)>, subs aren't optional from here anymore
208209 fn resolve_ty_assoc_item (
209210 & mut self ,
210211 ty : Ty ,
@@ -220,70 +221,66 @@ impl<'a> InferenceContext<'a> {
220221 }
221222
222223 let canonical_ty = self . canonicalize ( ty. clone ( ) ) ;
223- let traits_in_scope = self . resolver . traits_in_scope ( self . db . upcast ( ) ) ;
224224
225225 let mut not_visible = None ;
226226 let res = method_resolution:: iterate_method_candidates (
227227 & canonical_ty. value ,
228228 self . db ,
229229 self . table . trait_env . clone ( ) ,
230- & traits_in_scope ,
230+ self . get_traits_in_scope ( ) . as_ref ( ) . left_or_else ( | & it| it ) ,
231231 VisibleFromModule :: Filter ( self . resolver . module ( ) ) ,
232232 Some ( name) ,
233233 method_resolution:: LookupMode :: Path ,
234234 |_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-
269235 if visible {
270- Some ( ( def , item, Some ( substs ) , true ) )
236+ Some ( ( item, true ) )
271237 } else {
272238 if not_visible. is_none ( ) {
273- not_visible = Some ( ( def , item, Some ( substs ) , false ) ) ;
239+ not_visible = Some ( ( item, false ) ) ;
274240 }
275241 None
276242 }
277243 } ,
278244 ) ;
279245 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 )
284251 }
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 } ) ;
285282 }
286- res . map ( | ( def, _ , substs , _ ) | ( def , substs) )
283+ Some ( ( def, Some ( substs) ) )
287284 }
288285
289286 fn resolve_enum_variant_on_ty (
0 commit comments