]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Collect error instance instead of lambda functions
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 30 Aug 2023 15:13:36 +0000 (17:13 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:00:34 +0000 (19:00 +0100)
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>
gcc/rust/resolve/rust-early-name-resolver-2.0.cc
gcc/rust/resolve/rust-early-name-resolver-2.0.h
gcc/rust/rust-diagnostics.h
gcc/rust/rust-session-manager.cc

index a201bc4a78bad40c0bd80109818db50cee6f9bd7..e6603cf4fbd8adf3352f0d96f7ec094288bb31c1 100644 (file)
@@ -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;
     }
 
index 67785d0b60449a53adb01437f6742e85f6851f99..f2b63c9b6967843b8edc32f3a5cf49e8254eb6a7 100644 (file)
@@ -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
index ac7bf2a48f70cc00ca14d63ef529c681ce83c8cc..1ae4a292e77a92c975a194d697d80d9daa7cda52 100644 (file)
@@ -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.
index 8911e7d89aeed058eb91c44dade7b089553004ec..292506d5e573bb11ea4b57c5a88b4746fc25cd23 100644 (file)
@@ -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)
     {