[gccrs COMMIT] gccrs: Fix duplicate "trailing semicolon in macro used" warnings

gerris.rs@gmail.com gerris.rs@gmail.com
Wed Jul 15 00:36:22 GMT 2026


From: Yap Zhi Heng <yapzhhg@gmail.com>

gcc/rust/ChangeLog:

	* expand/rust-macro-expand.cc (transcribe_expression (Parser<MacroInvocLexer>)):
	Prevent the same trailing semicolon warning from being generated at the same loc.

Signed-Off-By: Yap Zhi Heng <yapzhhg@gmail.com>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: https://github.com/Rust-GCC/gccrs/commit/dc865d949654a0f181c55e3eeaac5d57a7a9f16f

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4686

 gcc/rust/expand/rust-macro-expand.cc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 2ab9d2541..30373722e 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -1012,9 +1012,14 @@ transcribe_expression (Parser<MacroInvocLexer> &parser)
   // 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");
+      // TODO bandaid for now, make this a member for MacroExpander instead in
+      // the future
+      static std::unordered_set<location_t> warned_loc;
+      auto locus = parser.peek_current_token ()->get_locus ();
+      if (warned_loc.insert (locus).second)
+	rust_warning_at (
+	  parser.peek_current_token ()->get_locus (), 0,
+	  "trailing semicolon in macro used in expression context");
       parser.skip_token ();
     }
 

base-commit: 970ba600872a6f4c431a4b59ce639456360b9bb4
-- 
2.54.0



More information about the Gcc-rust mailing list