public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: add missing name resolution to self params with specified types
@ 2023-04-06 21:35 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3cc5c9360c9454f7aa20717b6cfcc7085836233b

commit 3cc5c9360c9454f7aa20717b6cfcc7085836233b
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Wed Mar 29 14:24:12 2023 +0100

    gccrs: add missing name resolution to self params with specified types
    
    In rust it is possible to write method where you explicitly specify the
    type of a self param. It does not however allow for you to use reference
    destructuring in this senario.
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-ast-resolve-item.cc
            (ResolveTraitItems::visit): add name resolution self param
            (ResolveItem::visit): likewise
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-item.cc | 62 +++++++++++++++++++++++--------
 1 file changed, 46 insertions(+), 16 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index de863a036d5..0605acc49dc 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -138,16 +138,31 @@ ResolveTraitItems::visit (AST::TraitItemMethod &func)
 				       self_param.get_has_ref (),
 				       self_param.get_is_mut (),
 				       std::unique_ptr<AST::Pattern> (nullptr));
-
-  std::vector<std::unique_ptr<AST::TypePathSegment>> segments;
-  segments.push_back (std::unique_ptr<AST::TypePathSegment> (
-    new AST::TypePathSegment ("Self", false, self_param.get_locus ())));
-
-  AST::TypePath self_type_path (std::move (segments), self_param.get_locus ());
-
-  ResolveType::go (&self_type_path);
   PatternDeclaration::go (&self_pattern, Rib::ItemType::Param);
 
+  if (self_param.has_type ())
+    {
+      if (self_param.get_has_ref ())
+	{
+	  // FIXME is this true?
+	  rust_error_at (
+	    self_param.get_locus (),
+	    "it is not possible to mark self as reference and specify type");
+	}
+      ResolveType::go (self_param.get_type ().get ());
+    }
+  else
+    {
+      // here we implicitly make self have a type path of Self
+      std::vector<std::unique_ptr<AST::TypePathSegment>> segments;
+      segments.push_back (std::unique_ptr<AST::TypePathSegment> (
+	new AST::TypePathSegment ("Self", false, self_param.get_locus ())));
+
+      AST::TypePath self_type_path (std::move (segments),
+				    self_param.get_locus ());
+      ResolveType::go (&self_type_path);
+    }
+
   std::vector<PatternBinding> bindings
     = {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())};
 
@@ -636,16 +651,31 @@ ResolveItem::visit (AST::Method &method)
 				       self_param.get_has_ref (),
 				       self_param.get_is_mut (),
 				       std::unique_ptr<AST::Pattern> (nullptr));
-
-  std::vector<std::unique_ptr<AST::TypePathSegment>> segments;
-  segments.push_back (std::unique_ptr<AST::TypePathSegment> (
-    new AST::TypePathSegment ("Self", false, self_param.get_locus ())));
-
-  AST::TypePath self_type_path (std::move (segments), self_param.get_locus ());
-
-  ResolveType::go (&self_type_path);
   PatternDeclaration::go (&self_pattern, Rib::ItemType::Param);
 
+  if (self_param.has_type ())
+    {
+      if (self_param.get_has_ref ())
+	{
+	  // FIXME is this true?
+	  rust_error_at (
+	    self_param.get_locus (),
+	    "it is not possible to mark self as reference and specify type");
+	}
+      ResolveType::go (self_param.get_type ().get ());
+    }
+  else
+    {
+      // here we implicitly make self have a type path of Self
+      std::vector<std::unique_ptr<AST::TypePathSegment>> segments;
+      segments.push_back (std::unique_ptr<AST::TypePathSegment> (
+	new AST::TypePathSegment ("Self", false, self_param.get_locus ())));
+
+      AST::TypePath self_type_path (std::move (segments),
+				    self_param.get_locus ());
+      ResolveType::go (&self_type_path);
+    }
+
   std::vector<PatternBinding> bindings
     = {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())};

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

only message in thread, other threads:[~2023-04-06 21:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:35 [gcc/devel/rust/master] gccrs: add missing name resolution to self params with specified types 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).