@@ -119,9 +119,10 @@ class PathProbeType : public TypeCheckBase
119
119
static std::vector<PathProbeCandidate>
120
120
Probe (const TyTy::BaseType *receiver,
121
121
const HIR::PathIdentSegment &segment_name, bool probe_impls,
122
- bool probe_bounds, bool ignore_mandatory_trait_items)
122
+ bool probe_bounds, bool ignore_mandatory_trait_items,
123
+ DefId specific_trait_id = UNKNOWN_DEFID)
123
124
{
124
- PathProbeType probe (receiver, segment_name);
125
+ PathProbeType probe (receiver, segment_name, specific_trait_id );
125
126
if (probe_impls)
126
127
{
127
128
if (receiver->get_kind () == TyTy::TypeKind::ADT)
@@ -145,6 +146,13 @@ class PathProbeType : public TypeCheckBase
145
146
for (auto &candidate : probed_bounds)
146
147
{
147
148
const TraitReference *trait_ref = candidate.first ;
149
+ if (specific_trait_id != UNKNOWN_DEFID)
150
+ {
151
+ if (trait_ref->get_mappings ().get_defid ()
152
+ != specific_trait_id)
153
+ continue ;
154
+ }
155
+
148
156
HIR::ImplBlock *impl = candidate.second ;
149
157
probe.process_associated_trait_for_candidates (
150
158
trait_ref, impl, ignore_mandatory_trait_items);
@@ -154,6 +162,13 @@ class PathProbeType : public TypeCheckBase
154
162
for (const TyTy::TypeBoundPredicate &predicate :
155
163
receiver->get_specified_bounds ())
156
164
{
165
+ const TraitReference *trait_ref = predicate.get ();
166
+ if (specific_trait_id != UNKNOWN_DEFID)
167
+ {
168
+ if (trait_ref->get_mappings ().get_defid () != specific_trait_id)
169
+ continue ;
170
+ }
171
+
157
172
probe.process_predicate_for_candidates (predicate,
158
173
ignore_mandatory_trait_items);
159
174
}
@@ -221,6 +236,9 @@ class PathProbeType : public TypeCheckBase
221
236
protected:
222
237
void process_enum_item_for_candiates (const TyTy::ADTType *adt)
223
238
{
239
+ if (specific_trait_id != UNKNOWN_DEFID)
240
+ return ;
241
+
224
242
TyTy::VariantDef *v;
225
243
if (!adt->lookup_variant (search.as_string (), &v))
226
244
return ;
@@ -385,9 +403,9 @@ class PathProbeType : public TypeCheckBase
385
403
386
404
protected:
387
405
PathProbeType (const TyTy::BaseType *receiver,
388
- const HIR::PathIdentSegment &query)
406
+ const HIR::PathIdentSegment &query, DefId specific_trait_id )
389
407
: TypeCheckBase (), receiver (receiver), search (query),
390
- current_impl (nullptr )
408
+ current_impl (nullptr ), specific_trait_id (specific_trait_id)
391
409
{}
392
410
393
411
std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>>
@@ -427,6 +445,7 @@ class PathProbeType : public TypeCheckBase
427
445
const HIR::PathIdentSegment &search;
428
446
std::vector<PathProbeCandidate> candidates;
429
447
HIR::ImplBlock *current_impl;
448
+ DefId specific_trait_id;
430
449
};
431
450
432
451
class ReportMultipleCandidateError : private TypeCheckBase
@@ -507,7 +526,8 @@ class PathProbeImplTrait : public PathProbeType
507
526
PathProbeImplTrait (const TyTy::BaseType *receiver,
508
527
const HIR::PathIdentSegment &query,
509
528
const TraitReference *trait_reference)
510
- : PathProbeType (receiver, query), trait_reference (trait_reference)
529
+ : PathProbeType (receiver, query, UNKNOWN_DEFID),
530
+ trait_reference (trait_reference)
511
531
{}
512
532
513
533
const TraitReference *trait_reference;
0 commit comments