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
>From a7329b7fc0190920a9cf8bec77e34f2866b8af94 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <[email protected]>
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
--
Gcc-rust mailing list
[email protected]
https://gcc.gnu.org/mailman/listinfo/gcc-rust