public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Support inference of generic parameters on paths behind reference's
@ 2022-06-08 12:37 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:37 UTC (permalink / raw)
  To: gcc-cvs

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

commit e69e162462c6fb3d886460d96ce649207b7c9e3f
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Mon Apr 25 17:48:09 2022 +0100

    Support inference of generic parameters on paths behind reference's
    
    We used a hack in the parser to turn simple cases such as &Foo(..) into:
    
      BorrowExpr
        CallExpr(
          IdentifierExpr + <Argument-expressions>))
    
    The IdentifierExpr here is parsed as a PathExpression but to simplify
    things at the time it seemed logic to see these as identifier expressions
    but this is actually a Path and we need to be careful about generic
    arguments here. Identifiers are simply identifiers and must not be changed
    or coherence of inference variables will become a jumble of inference
    variables trying to infer one another inside purely generic code.
    
    This patch leaves the PathInExpressions as Path's instead of trying to be
    clever and turn them into identifiers.
    
    Fixes #1165

Diff:
---
 gcc/rust/parse/rust-parse-impl.h         | 20 --------------------
 gcc/testsuite/rust/compile/issue-1165.rs |  5 +++++
 2 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 25979cec560..6715a778233 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -12591,16 +12591,6 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
 	      // struct/enum expr struct
 	      if (!restrictions.can_be_struct_expr && !not_a_block)
 		{
-		  // assume path is returned if not single segment
-		  if (path.is_single_segment ())
-		    {
-		      // have to return an identifier expression or something
-		      /* HACK: may have to become permanent, but this is my
-		       * current identifier expression */
-		      return std::unique_ptr<AST::IdentifierExpr> (
-			new AST::IdentifierExpr (tok->get_str (), {},
-						 tok->get_locus ()));
-		    }
 		  // HACK: add outer attrs to path
 		  path.set_outer_attrs (std::move (outer_attrs));
 		  return std::unique_ptr<AST::PathInExpression> (
@@ -12613,16 +12603,6 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
 	    // struct/enum expr tuple
 	    if (!restrictions.can_be_struct_expr)
 	      {
-		// assume path is returned if not single segment
-		if (path.is_single_segment ())
-		  {
-		    // have to return an identifier expression or something, idk
-		    /* HACK: may have to become permanent, but this is my
-		     * current identifier expression */
-		    return std::unique_ptr<AST::IdentifierExpr> (
-		      new AST::IdentifierExpr (tok->get_str (), {},
-					       tok->get_locus ()));
-		  }
 		// HACK: add outer attrs to path
 		path.set_outer_attrs (std::move (outer_attrs));
 		return std::unique_ptr<AST::PathInExpression> (
diff --git a/gcc/testsuite/rust/compile/issue-1165.rs b/gcc/testsuite/rust/compile/issue-1165.rs
new file mode 100644
index 00000000000..f5889698d70
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1165.rs
@@ -0,0 +1,5 @@
+struct Foo<T>(T);
+
+fn main() {
+    &Foo(123);
+}


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

only message in thread, other threads:[~2022-06-08 12:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:37 [gcc/devel/rust/master] Support inference of generic parameters on paths behind reference's 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).