public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-7643] gccrs: Allow parsing a borrow from struct expression
Date: Tue, 16 Jan 2024 17:50:00 +0000 (GMT)	[thread overview]
Message-ID: <20240116175000.0B9C53858436@sourceware.org> (raw)

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

commit r14-7643-gb436709f4b1b0d75fa0b5f1c6c6b22f397a767c9
Author: Owen Avery <powerboat9.gamer@gmail.com>
Date:   Mon Jun 5 16:48:55 2023 -0400

    gccrs: Allow parsing a borrow from struct expression
    
    gcc/rust/ChangeLog:
    
            * parse/rust-parse-impl.h
            (Parser::null_denotation): Allow struct expression referencing.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/struct-expr-parse.rs: New test.
    
    Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>

Diff:
---
 gcc/rust/parse/rust-parse-impl.h                | 5 ++---
 gcc/testsuite/rust/compile/struct-expr-parse.rs | 7 +++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 9faa374915c..80ffbcc22f9 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -12633,11 +12633,10 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
 	std::unique_ptr<AST::Expr> expr = nullptr;
 	bool is_mut_borrow = false;
 
-	/* HACK: as struct expressions should always be value expressions,
-	 * cannot be referenced */
 	ParseRestrictions entered_from_unary;
 	entered_from_unary.entered_from_unary = true;
-	entered_from_unary.can_be_struct_expr = false;
+	if (!restrictions.can_be_struct_expr)
+	  entered_from_unary.can_be_struct_expr = false;
 
 	if (lexer.peek_token ()->get_id () == MUT)
 	  {
diff --git a/gcc/testsuite/rust/compile/struct-expr-parse.rs b/gcc/testsuite/rust/compile/struct-expr-parse.rs
new file mode 100644
index 00000000000..3c383a90ca4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/struct-expr-parse.rs
@@ -0,0 +1,7 @@
+struct A { // { dg-warning "struct is never constructed" }
+    a: u32
+}
+
+pub fn foo(a: u32) {
+    (&A { a }.a, 1);
+}

                 reply	other threads:[~2024-01-16 17:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116175000.0B9C53858436@sourceware.org \
    --to=cohenarthur@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).