Skip to content

Commit 5e735e9

Browse files
powerboat9philberty
authored andcommitted
Ignore semicolon following a macro expansion in expression context
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 <[email protected]>
1 parent c8679a6 commit 5e735e9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

gcc/rust/expand/rust-macro-expand.cc

+9
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,15 @@ transcribe_expression (Parser<MacroInvocLexer> &parser)
911911
if (expr == nullptr)
912912
return AST::Fragment::create_error ();
913913

914+
// FIXME: make this an error for some edititons
915+
if (parser.peek_current_token ()->get_id () == SEMICOLON)
916+
{
917+
rust_warning_at (
918+
parser.peek_current_token ()->get_locus (), 0,
919+
"trailing semicolon in macro used in expression context");
920+
parser.skip_token ();
921+
}
922+
914923
auto end = lexer.get_offs ();
915924

916925
return AST::Fragment ({std::move (expr)}, lexer.get_token_slice (start, end));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
macro_rules! mac {
2+
() => {();} // { dg-warning "trailing semicolon" }
3+
}
4+
5+
pub fn foo() {
6+
mac!()
7+
}

0 commit comments

Comments
 (0)