@@ -142,31 +142,35 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
142
142
return ;
143
143
}
144
144
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
145
155
std::unique_ptr<HIR::TypePathSegment> &item_seg
146
156
= 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 ())
152
161
{
153
162
rust_error_at (item_seg->get_locus (), " unknown associated item" );
154
163
return ;
155
164
}
156
165
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);
165
168
166
169
// we need resolve to the impl block
167
170
NodeId impl_resolved_id = UNKNOWN_NODEID;
168
171
bool have_associated_impl = resolver->lookup_resolved_name (
169
172
qual_path_type.get_mappings ().get_nodeid (), &impl_resolved_id);
173
+ AssociatedImplTrait *lookup_associated = nullptr ;
170
174
if (have_associated_impl)
171
175
{
172
176
HirId impl_block_id;
@@ -175,30 +179,16 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
175
179
impl_resolved_id, &impl_block_id);
176
180
rust_assert (ok);
177
181
178
- AssociatedImplTrait *lookup_associated = nullptr ;
179
182
bool found_impl_trait
180
183
= context->lookup_associated_trait_impl (impl_block_id,
181
184
&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)
197
186
{
198
- translated = p-> resolve ( );
187
+ lookup_associated-> setup_associated_types (root, specified_bound );
199
188
}
200
189
}
201
190
191
+ // turbo-fish segment path::<ty>
202
192
if (item_seg->get_type () == HIR::TypePathSegment::SegmentType::GENERIC)
203
193
{
204
194
HIR::TypePathSegmentGeneric &generic_seg
@@ -222,6 +212,7 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
222
212
}
223
213
224
214
// continue on as a path-in-expression
215
+ const TraitItemReference *trait_item_ref = item.get_raw_item ();
225
216
NodeId root_resolved_node_id = trait_item_ref->get_mappings ().get_nodeid ();
226
217
bool fully_resolved = path.get_segments ().empty ();
227
218
if (fully_resolved)
@@ -448,22 +439,6 @@ TypeCheckType::resolve_segments (
448
439
{
449
440
resolved_node_id
450
441
= 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
- }
467
442
}
468
443
469
444
if (seg->is_generic_segment ())
0 commit comments