Skip to content

Commit

Permalink
Ignore semicolon following a macro expansion in expression context
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* expand/rust-macro-expand.cc
	(transcribe_expression): Skip trailing semicolon.

gcc/testsuite/ChangeLog:

	* rust/compile/macro-issue2273.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
  • Loading branch information
powerboat9 authored and philberty committed Jul 6, 2023
1 parent c8679a6 commit 5e735e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gcc/rust/expand/rust-macro-expand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,15 @@ transcribe_expression (Parser<MacroInvocLexer> &parser)
if (expr == nullptr)
return AST::Fragment::create_error ();

// FIXME: make this an error for some edititons
if (parser.peek_current_token ()->get_id () == SEMICOLON)
{
rust_warning_at (
parser.peek_current_token ()->get_locus (), 0,
"trailing semicolon in macro used in expression context");
parser.skip_token ();
}

auto end = lexer.get_offs ();

return AST::Fragment ({std::move (expr)}, lexer.get_token_slice (start, end));
Expand Down
7 changes: 7 additions & 0 deletions gcc/testsuite/rust/compile/macro-issue2273.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
macro_rules! mac {
() => {();} // { dg-warning "trailing semicolon" }
}

pub fn foo() {
mac!()
}

0 comments on commit 5e735e9

Please sign in to comment.