Skip to content

Commit e421059

Browse files
committed
Return an error type on macro invoc parsing failure
No check was performed and the value was assumed non null. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_stmt_or_expr): Add null check on parse_macro_invocation_partial call. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
1 parent 5b7a0d7 commit e421059

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

gcc/rust/parse/rust-parse-impl.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11760,6 +11760,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
1176011760
std::unique_ptr<AST::MacroInvocation> invoc
1176111761
= parse_macro_invocation_partial (std::move (path),
1176211762
std::move (outer_attrs));
11763+
if (invoc == nullptr)
11764+
return ExprOrStmt::create_error ();
1176311765

1176411766
if (restrictions.consume_semi && maybe_skip_token (SEMICOLON))
1176511767
{
@@ -11771,9 +11773,12 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
1177111773

1177211774
TokenId after_macro = lexer.peek_token ()->get_id ();
1177311775

11774-
if (invoc->get_invoc_data ().get_delim_tok_tree ().get_delim_type ()
11775-
== AST::CURLY
11776-
&& after_macro != DOT && after_macro != QUESTION_MARK)
11776+
AST::DelimType delim_type = invoc->get_invoc_data ()
11777+
.get_delim_tok_tree ()
11778+
.get_delim_type ();
11779+
11780+
if (delim_type == AST::CURLY && after_macro != DOT
11781+
&& after_macro != QUESTION_MARK)
1177711782
{
1177811783
rust_debug ("braced macro statement");
1177911784
return ExprOrStmt (

0 commit comments

Comments
 (0)