]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Emit errors from the transcriber when they occur
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 18 Sep 2025 14:57:15 +0000 (16:57 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 20:30:53 +0000 (21:30 +0100)
Emitting the errors later means some error could be emitted multiple
times.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (transcribe_expression): Emit error
early.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/expand/rust-macro-expand.cc

index 662cc61fb860e3018a8eae2f22930d1890856f4f..ec4f666dc7b3d0a79c344c22294a090cddccf28f 100644 (file)
@@ -963,7 +963,11 @@ transcribe_expression (Parser<MacroInvocLexer> &parser)
   auto attrs = parser.parse_outer_attributes ();
   auto expr = parser.parse_expr (std::move (attrs));
   if (expr == nullptr)
-    return AST::Fragment::create_error ();
+    {
+      for (auto error : parser.get_errors ())
+       error.emit ();
+      return AST::Fragment::create_error ();
+    }
 
   // FIXME: make this an error for some edititons
   if (parser.peek_current_token ()->get_id () == SEMICOLON)
@@ -1152,11 +1156,7 @@ MacroExpander::transcribe_rule (
 
   // emit any errors
   if (parser.has_errors ())
-    {
-      for (auto &err : parser.get_errors ())
-       rust_error_at (err.locus, "%s", err.message.c_str ());
-      return AST::Fragment::create_error ();
-    }
+    return AST::Fragment::create_error ();
 
   // are all the tokens used?
   bool did_delimit = parser.skip_token (last_token_id);