@@ -142,31 +142,35 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
142142 return ;
143143 }
144144
145+ // get the predicate for the bound
146+ auto specified_bound
147+ = get_predicate_from_bound (*qual_path_type.get_trait ().get ());
148+ if (specified_bound.is_error ())
149+ return ;
150+
151+ // inherit the bound
152+ root->inherit_bounds ({specified_bound});
153+
154+ // lookup the associated item from the specified bound
145155 std::unique_ptr<HIR::TypePathSegment> &item_seg
146156 = path.get_associated_segment ();
147- const TraitItemReference *trait_item_ref = nullptr ;
148- bool ok
149- = trait_ref->lookup_trait_item (item_seg->get_ident_segment ().as_string (),
150- &trait_item_ref);
151- if (!ok)
157+ HIR::PathIdentSegment item_seg_identifier = item_seg->get_ident_segment ();
158+ TyTy::TypeBoundPredicateItem item
159+ = specified_bound.lookup_associated_item (item_seg_identifier.as_string ());
160+ if (item.is_error ())
152161 {
153162 rust_error_at (item_seg->get_locus (), " unknown associated item" );
154163 return ;
155164 }
156165
157- // this will be the placeholder from the trait but we may be able to project
158- // it based on the impl block
159- translated = trait_item_ref->get_tyty ();
160-
161- // this is the associated generics we need to potentially apply
162- HIR::GenericArgs trait_generics = qual_path_type.trait_has_generic_args ()
163- ? qual_path_type.get_trait_generic_args ()
164- : HIR::GenericArgs::create_empty ();
166+ // infer the root type
167+ translated = item.get_tyty_for_receiver (root);
165168
166169 // we need resolve to the impl block
167170 NodeId impl_resolved_id = UNKNOWN_NODEID;
168171 bool have_associated_impl = resolver->lookup_resolved_name (
169172 qual_path_type.get_mappings ().get_nodeid (), &impl_resolved_id);
173+ AssociatedImplTrait *lookup_associated = nullptr ;
170174 if (have_associated_impl)
171175 {
172176 HirId impl_block_id;
@@ -175,30 +179,16 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
175179 impl_resolved_id, &impl_block_id);
176180 rust_assert (ok);
177181
178- AssociatedImplTrait *lookup_associated = nullptr ;
179182 bool found_impl_trait
180183 = context->lookup_associated_trait_impl (impl_block_id,
181184 &lookup_associated);
182- rust_assert (found_impl_trait);
183-
184- // project
185- lookup_associated->setup_associated_types ();
186- translated = lookup_associated->get_projected_type (
187- trait_item_ref, root, item_seg->get_mappings ().get_hirid (),
188- trait_generics, item_seg->get_locus ());
189- }
190-
191- if (translated->get_kind () == TyTy::TypeKind::PLACEHOLDER)
192- {
193- // lets grab the actual projection type
194- TyTy::PlaceholderType *p
195- = static_cast <TyTy::PlaceholderType *> (translated);
196- if (p->can_resolve ())
185+ if (found_impl_trait)
197186 {
198- translated = p-> resolve ( );
187+ lookup_associated-> setup_associated_types (root, specified_bound );
199188 }
200189 }
201190
191+ // turbo-fish segment path::<ty>
202192 if (item_seg->get_type () == HIR::TypePathSegment::SegmentType::GENERIC)
203193 {
204194 HIR::TypePathSegmentGeneric &generic_seg
@@ -222,6 +212,7 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
222212 }
223213
224214 // continue on as a path-in-expression
215+ const TraitItemReference *trait_item_ref = item.get_raw_item ();
225216 NodeId root_resolved_node_id = trait_item_ref->get_mappings ().get_nodeid ();
226217 bool fully_resolved = path.get_segments ().empty ();
227218 if (fully_resolved)
@@ -448,22 +439,6 @@ TypeCheckType::resolve_segments (
448439 {
449440 resolved_node_id
450441 = candidate.item .trait .item_ref ->get_mappings ().get_nodeid ();
451-
452- // lookup the associated-impl-trait
453- HIR::ImplBlock *impl = candidate.item .trait .impl ;
454- if (impl != nullptr && !reciever_is_generic)
455- {
456- AssociatedImplTrait *lookup_associated = nullptr ;
457- bool found_impl_trait = context->lookup_associated_trait_impl (
458- impl->get_mappings ().get_hirid (), &lookup_associated);
459- rust_assert (found_impl_trait);
460-
461- lookup_associated->setup_associated_types ();
462-
463- // we need a new ty_ref_id for this trait item
464- tyseg = tyseg->clone ();
465- tyseg->set_ty_ref (mappings->get_next_hir_id ());
466- }
467442 }
468443
469444 if (seg->is_generic_segment ())
0 commit comments