From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id D44CE3848407 for ; Wed, 21 Jul 2021 23:09:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D44CE3848407 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x18.wildebeest.org [172.31.17.154]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 3EF64300066F for ; Thu, 22 Jul 2021 01:09:39 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id 0C31E2E8071C; Thu, 22 Jul 2021 01:09:39 +0200 (CEST) Date: Thu, 22 Jul 2021 01:09:38 +0200 From: Mark Wielaard To: gcc-rust@gcc.gnu.org Subject: Re: Using unsafe blocks in let expressions Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="PveM4QZtBN79Hhv3" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jul 2021 23:09:42 -0000 --PveM4QZtBN79Hhv3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Jul 21, 2021 at 11:09:38PM +0200, Mark Wielaard wrote: > + Location locus; > + if (!pratt_parse) > + { > + Location locus = lexer.peek_token ()->get_locus (); Oops, shadowed locus. Fixed patch attached, and also at https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=let-unsafe --PveM4QZtBN79Hhv3 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-unsafe-blocks-can-be-used-in-expressions.patch" >From a7329b7fc0190920a9cf8bec77e34f2866b8af94 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 21 Jul 2021 22:41:04 +0200 Subject: [PATCH] unsafe blocks can be used in expressions To use an unsafe block expression handle it in null_denotation for the pratt parser. Adjust parse_unsafe_block_expr to take a pratt_parse bool that defaults to false. --- gcc/rust/parse/rust-parse-impl.h | 15 ++++++++++++--- gcc/rust/parse/rust-parse.h | 5 +++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index eedc76db43e..bdf1e09a029 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -8704,10 +8704,17 @@ Parser::parse_async_block_expr (AST::AttrVec outer_attrs) // Parses an unsafe block expression. template std::unique_ptr -Parser::parse_unsafe_block_expr (AST::AttrVec outer_attrs) +Parser::parse_unsafe_block_expr (AST::AttrVec outer_attrs, + bool pratt_parse) { - Location locus = lexer.peek_token ()->get_locus (); - skip_token (UNSAFE); + Location locus; + if (!pratt_parse) + { + locus = lexer.peek_token ()->get_locus (); + skip_token (UNSAFE); + } + else + locus = lexer.peek_token ()->get_locus () - 1; // parse block expression (required) std::unique_ptr block_expr = parse_block_expr (); @@ -12823,6 +12830,8 @@ Parser::null_denotation (const_TokenPtr tok, case LEFT_SQUARE: // array definition expr (not indexing) return parse_array_expr (std::move (outer_attrs), true); + case UNSAFE: + return parse_unsafe_block_expr (std::move (outer_attrs), true); default: if (!restrictions.expr_can_be_null) add_error (Error (tok->get_locus (), diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 1cd85eae8c2..1c7bd781b3f 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -504,8 +504,6 @@ private: AST::LoopLabel parse_loop_label (); std::unique_ptr parse_async_block_expr (AST::AttrVec outer_attrs = AST::AttrVec ()); - std::unique_ptr - parse_unsafe_block_expr (AST::AttrVec outer_attrs = AST::AttrVec ()); std::unique_ptr parse_grouped_expr (AST::AttrVec outer_attrs = AST::AttrVec ()); std::unique_ptr parse_closure_expr (AST::AttrVec outer_attrs @@ -522,6 +520,9 @@ private: std::unique_ptr parse_continue_expr (AST::AttrVec outer_attrs = AST::AttrVec (), bool pratt_parse = false); + std::unique_ptr + parse_unsafe_block_expr (AST::AttrVec outer_attrs = AST::AttrVec (), + bool pratt_parse = false); std::unique_ptr parse_array_expr (AST::AttrVec outer_attrs = AST::AttrVec (), bool pratt_parse = false); -- 2.32.0 --PveM4QZtBN79Hhv3--