From: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

        * typecheck/rust-hir-type-bounds.h: optional trait arg
        * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): 
likewise
        (TypeBoundsProbe::Probe): likewise
        (TypeBoundsProbe::is_bound_satisfied_for_type): use specified trait
        (TypeBoundsProbe::scan): try to scan for indexed traits

Signed-off-by: Philip Herron <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/17eec6b39b01e7bd4c272796889c79c4bd751686

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4816

 gcc/rust/typecheck/rust-hir-type-bounds.h |  5 +++--
 gcc/rust/typecheck/rust-tyty-bounds.cc    | 25 +++++++++++++++--------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-bounds.h 
b/gcc/rust/typecheck/rust-hir-type-bounds.h
index bede69406..3dbc47ec7 100644
--- a/gcc/rust/typecheck/rust-hir-type-bounds.h
+++ b/gcc/rust/typecheck/rust-hir-type-bounds.h
@@ -30,7 +30,7 @@ class TypeBoundsProbe : public TypeCheckBase
 {
 public:
   static std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
-  Probe (TyTy::BaseType *receiver);
+  Probe (TyTy::BaseType *receiver, const HIR::Trait *specified_trait = 
nullptr);
 
   static bool is_bound_satisfied_for_type (TyTy::BaseType *receiver,
                                           TraitReference *ref);
@@ -46,9 +46,10 @@ private:
   void assemble_builtin_candidate (LangItem::Kind item);
 
 private:
-  TypeBoundsProbe (TyTy::BaseType *receiver);
+  TypeBoundsProbe (TyTy::BaseType *receiver, const HIR::Trait 
*specified_trait);
 
   TyTy::BaseType *receiver;
+  const HIR::Trait *specified_trait;
   std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> trait_references;
 };
 
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc 
b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 21a55ac6c..86aa06d27 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -26,14 +26,16 @@
 namespace Rust {
 namespace Resolver {
 
-TypeBoundsProbe::TypeBoundsProbe (TyTy::BaseType *receiver)
-  : TypeCheckBase (), receiver (receiver)
+TypeBoundsProbe::TypeBoundsProbe (TyTy::BaseType *receiver,
+                                 const HIR::Trait *specified_trait)
+  : TypeCheckBase (), receiver (receiver), specified_trait (specified_trait)
 {}
 
 std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
-TypeBoundsProbe::Probe (TyTy::BaseType *receiver)
+TypeBoundsProbe::Probe (TyTy::BaseType *receiver,
+                       const HIR::Trait *specified_trait)
 {
-  TypeBoundsProbe probe (receiver);
+  TypeBoundsProbe probe (receiver, specified_trait);
   probe.scan ();
   return probe.trait_references;
 }
@@ -50,7 +52,7 @@ TypeBoundsProbe::is_bound_satisfied_for_type (TyTy::BaseType 
*receiver,
     }
 
   std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> bounds
-    = Probe (receiver);
+    = Probe (receiver, ref->get_hir_trait_ref ());
   for (auto &bound : bounds)
     {
       const TraitReference *b = bound.first;
@@ -95,10 +97,15 @@ TypeBoundsProbe::scan ()
 {
   std::vector<std::pair<HIR::TypePath *, HIR::ImplBlock *>>
     possible_trait_paths;
-  mappings.iterate_impl_blocks (
-    [&] (HirId id, HIR::ImplBlock *impl) mutable -> bool {
-      return process_impl_block (id, impl, possible_trait_paths);
-    });
+  auto process_impl = [&] (HirId id, HIR::ImplBlock *impl) mutable -> bool {
+    return process_impl_block (id, impl, possible_trait_paths);
+  };
+
+  if (specified_trait == nullptr)
+    mappings.iterate_impl_blocks (process_impl);
+  else
+    mappings.iterate_trait_impl_blocks (
+      specified_trait->get_mappings ().get_nodeid (), process_impl);
 
   for (auto &path : possible_trait_paths)
     {
-- 
2.55.0

Reply via email to