From: Mark Wielaard <mark@klomp.org>
To: gcc-rust@gcc.gnu.org
Subject: Re: Using unsafe blocks in let expressions
Date: Thu, 22 Jul 2021 01:09:38 +0200 [thread overview]
Message-ID: <YPipMlAPpAVpwmhY@wildebeest.org> (raw)
In-Reply-To: <YPiNEmKxln7rgJ57@wildebeest.org>
[-- Attachment #1: Type: text/plain, Size: 305 bytes --]
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
[-- Attachment #2: 0001-unsafe-blocks-can-be-used-in-expressions.patch --]
[-- Type: text/x-diff, Size: 3068 bytes --]
From a7329b7fc0190920a9cf8bec77e34f2866b8af94 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
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<ManagedTokenSource>::parse_async_block_expr (AST::AttrVec outer_attrs)
// Parses an unsafe block expression.
template <typename ManagedTokenSource>
std::unique_ptr<AST::UnsafeBlockExpr>
-Parser<ManagedTokenSource>::parse_unsafe_block_expr (AST::AttrVec outer_attrs)
+Parser<ManagedTokenSource>::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<AST::BlockExpr> block_expr = parse_block_expr ();
@@ -12823,6 +12830,8 @@ Parser<ManagedTokenSource>::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<AST::AsyncBlockExpr>
parse_async_block_expr (AST::AttrVec outer_attrs = AST::AttrVec ());
- std::unique_ptr<AST::UnsafeBlockExpr>
- parse_unsafe_block_expr (AST::AttrVec outer_attrs = AST::AttrVec ());
std::unique_ptr<AST::GroupedExpr> parse_grouped_expr (AST::AttrVec outer_attrs
= AST::AttrVec ());
std::unique_ptr<AST::ClosureExpr> parse_closure_expr (AST::AttrVec outer_attrs
@@ -522,6 +520,9 @@ private:
std::unique_ptr<AST::ContinueExpr>
parse_continue_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
bool pratt_parse = false);
+ std::unique_ptr<AST::UnsafeBlockExpr>
+ parse_unsafe_block_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
+ bool pratt_parse = false);
std::unique_ptr<AST::ArrayExpr> parse_array_expr (AST::AttrVec outer_attrs
= AST::AttrVec (),
bool pratt_parse = false);
--
2.32.0
next prev parent reply other threads:[~2021-07-21 23:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 21:09 Mark Wielaard
2021-07-21 23:09 ` Mark Wielaard [this message]
2021-07-23 11:23 ` Philip Herron
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=YPipMlAPpAVpwmhY@wildebeest.org \
--to=mark@klomp.org \
--cc=gcc-rust@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).