From: Pierre-Emmanuel Patry Date: Wed, 30 Aug 2023 15:13:36 +0000 (+0200) Subject: gccrs: Collect error instance instead of lambda functions X-Git-Tag: basepoints/gcc-15~2189 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11963393d073a4e54d2e25fccac2962cb66b2dd3;p=thirdparty%2Fgcc.git 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 --- 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 a201bc4a78ba..e6603cf4fbd8 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 67785d0b6044..f2b63c9b6967 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; - class Early : public DefaultResolver { using DefaultResolver::visit; @@ -39,7 +37,7 @@ public: void go (AST::Crate &crate); - const std::vector &get_macro_resolve_errors () const + const std::vector &get_macro_resolve_errors () const { return macro_resolve_errors; } @@ -83,9 +81,9 @@ private: }; TextualScope textual_scope; - std::vector macro_resolve_errors; + std::vector 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 ac7bf2a48f70..1ae4a292e77a 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 8911e7d89aee..292506d5e573 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 macro_errors; + std::vector 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) {