public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: resolve the associated_predicate when mapping Fn traits
@ 2023-05-02  7:11 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-05-02  7:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ca1f50ba61be3fe9774cbd0783c8ab6f6b51e5b2

commit ca1f50ba61be3fe9774cbd0783c8ab6f6b51e5b2
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Thu Apr 20 11:12:29 2023 +0100

    gccrs: resolve the associated_predicate when mapping Fn traits
    
    This is required to solve #2105
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call):
            return the assoicated predicate
            * typecheck/rust-hir-type-check-expr.h: update prototype
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 14 ++++++++++----
 gcc/rust/typecheck/rust-hir-type-check-expr.h  |  4 ++--
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 704ca2b9e5b..8d2e89ba0d7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1784,7 +1784,7 @@ TypeCheckExpr::resolve_operator_overload (
 
 HIR::PathIdentSegment
 TypeCheckExpr::resolve_possible_fn_trait_call_method_name (
-  const TyTy::BaseType &receiver)
+  TyTy::BaseType &receiver, TyTy::TypeBoundPredicate *associated_predicate)
 {
   // Question
   // do we need to probe possible bounds here? I think not, i think when we
@@ -1793,7 +1793,7 @@ TypeCheckExpr::resolve_possible_fn_trait_call_method_name (
   // FIXME
   // the logic to map the FnTrait to their respective call trait-item is
   // duplicated over in the backend/rust-compile-expr.cc
-  for (const auto &bound : receiver.get_specified_bounds ())
+  for (auto &bound : receiver.get_specified_bounds ())
     {
       bool found_fn = bound.get_name ().compare ("Fn") == 0;
       bool found_fn_mut = bound.get_name ().compare ("FnMut") == 0;
@@ -1801,19 +1801,23 @@ TypeCheckExpr::resolve_possible_fn_trait_call_method_name (
 
       if (found_fn)
 	{
+	  *associated_predicate = bound;
 	  return HIR::PathIdentSegment ("call");
 	}
       else if (found_fn_mut)
 	{
+	  *associated_predicate = bound;
 	  return HIR::PathIdentSegment ("call_mut");
 	}
       else if (found_fn_once)
 	{
+	  *associated_predicate = bound;
 	  return HIR::PathIdentSegment ("call_once");
 	}
     }
 
   // nothing
+  *associated_predicate = TyTy::TypeBoundPredicate::error ();
   return HIR::PathIdentSegment ("");
 }
 
@@ -1823,9 +1827,11 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr,
 				      TyTy::BaseType **result)
 {
   // we turn this into a method call expr
+  auto associated_predicate = TyTy::TypeBoundPredicate::error ();
   HIR::PathIdentSegment method_name
-    = resolve_possible_fn_trait_call_method_name (*receiver_tyty);
-  if (method_name.is_error ())
+    = resolve_possible_fn_trait_call_method_name (*receiver_tyty,
+						  &associated_predicate);
+  if (method_name.is_error () || associated_predicate.is_error ())
     return false;
 
   auto candidates = MethodResolver::Probe (receiver_tyty, method_name);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 5be9bcdb3f1..1a9591f1d49 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -97,8 +97,8 @@ protected:
 			      TyTy::BaseType *function_tyty,
 			      TyTy::BaseType **result);
 
-  HIR::PathIdentSegment
-  resolve_possible_fn_trait_call_method_name (const TyTy::BaseType &receiver);
+  HIR::PathIdentSegment resolve_possible_fn_trait_call_method_name (
+    TyTy::BaseType &receiver, TyTy::TypeBoundPredicate *associated_predicate);
 
 private:
   TypeCheckExpr ();

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-02  7:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02  7:11 [gcc/devel/rust/master] gccrs: resolve the associated_predicate when mapping Fn traits Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).