diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-06-05 16:48:55 -0400 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:46:24 +0100 |
commit | b436709f4b1b0d75fa0b5f1c6c6b22f397a767c9 (patch) | |
tree | 1f4f40957b757693a856bb80404e1fc0fa6e8177 /gcc | |
parent | d4ac20b6b426f92d536806ecbb05722570a2e605 (diff) | |
download | gcc-b436709f4b1b0d75fa0b5f1c6c6b22f397a767c9.zip gcc-b436709f4b1b0d75fa0b5f1c6c6b22f397a767c9.tar.gz gcc-b436709f4b1b0d75fa0b5f1c6c6b22f397a767c9.tar.bz2 |
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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 5 | ||||
-rw-r--r-- | 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 9faa374..80ffbcc 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 0000000..3c383a9 --- /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); +} |