[gcc r14-7950] gccrs: Collect error instance instead of lambda functions

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:10:00 GMT 2024


https://gcc.gnu.org/g:11963393d073a4e54d2e25fccac2962cb66b2dd3

commit r14-7950-g11963393d073a4e54d2e25fccac2962cb66b2dd3
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed Aug 30 17:13:36 2023 +0200

    gccrs: Collect error instance instead of lambda functions
    
    Use error object instead of lambda for error collection.
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-early-name-resolver-2.0.cc (Early::visit):
            Collect error instead of lambda.
            * resolve/rust-early-name-resolver-2.0.h (std::function<void):
            Remove type alias.
            * rust-diagnostics.h: Change collection type.
            * rust-session-manager.cc (Session::expansion): Change
            collection container.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 6 ++----
 gcc/rust/resolve/rust-early-name-resolver-2.0.h  | 8 +++-----
 gcc/rust/rust-diagnostics.h                      | 1 +
 gcc/rust/rust-session-manager.cc                 | 4 ++--
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index a201bc4a78b..e6603cf4fbd 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -135,10 +135,8 @@ Early::visit (AST::MacroInvocation &invoc)
   // if the definition still does not have a value, then it's an error
   if (!definition.has_value ())
     {
-      collect_error ([&] () {
-	rust_error_at (invoc.get_locus (), ErrorCode::E0433,
-		       "could not resolve macro invocation");
-      });
+      collect_error (Error (invoc.get_locus (), ErrorCode::E0433,
+			    "could not resolve macro invocation"));
       return;
     }
 
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.h b/gcc/rust/resolve/rust-early-name-resolver-2.0.h
index 67785d0b604..f2b63c9b696 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.h
@@ -28,8 +28,6 @@
 namespace Rust {
 namespace Resolver2_0 {
 
-using ResolveError = std::function<void ()>;
-
 class Early : public DefaultResolver
 {
   using DefaultResolver::visit;
@@ -39,7 +37,7 @@ public:
 
   void go (AST::Crate &crate);
 
-  const std::vector<ResolveError> &get_macro_resolve_errors () const
+  const std::vector<Error> &get_macro_resolve_errors () const
   {
     return macro_resolve_errors;
   }
@@ -83,9 +81,9 @@ private:
   };
 
   TextualScope textual_scope;
-  std::vector<ResolveError> macro_resolve_errors;
+  std::vector<Error> macro_resolve_errors;
 
-  void collect_error (ResolveError e) { macro_resolve_errors.push_back (e); }
+  void collect_error (Error e) { macro_resolve_errors.push_back (e); }
 };
 
 } // namespace Resolver2_0
diff --git a/gcc/rust/rust-diagnostics.h b/gcc/rust/rust-diagnostics.h
index ac7bf2a48f7..1ae4a292e77 100644
--- a/gcc/rust/rust-diagnostics.h
+++ b/gcc/rust/rust-diagnostics.h
@@ -22,6 +22,7 @@
 #define RUST_DIAGNOSTICS_H
 
 #include "rust-linemap.h"
+#include "util/optional.h"
 
 // This macro is used to specify the position of format string & it's
 // arguments within the function's paramter list.
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 8911e7d89ae..292506d5e57 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -874,7 +874,7 @@ Session::expansion (AST::Crate &crate)
   /* expand by calling cxtctxt object's monotonic_expander's expand_crate
    * method. */
   MacroExpander expander (crate, cfg, *this);
-  std::vector<Resolver2_0::ResolveError> macro_errors;
+  std::vector<Error> macro_errors;
 
   while (!fixed_point_reached && iterations < cfg.recursion_limit)
     {
@@ -903,7 +903,7 @@ Session::expansion (AST::Crate &crate)
 
   // Fixed point reached: Emit unresolved macros error
   for (auto &error : macro_errors)
-    error ();
+    error.emit ();
 
   if (iterations == cfg.recursion_limit)
     {


More information about the Gcc-cvs mailing list