From: Pierre-Emmanuel Patry <[email protected]>

gcc/rust/ChangeLog:

        * rust-session-manager.cc (Session::enable_dump): Rework error message
        and remove magic value.
        (Session::handle_excluded_node): Remove static buffer size.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
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/0aa6c5ba9ddf3ad712fae44362de68c59275f41c

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

 gcc/rust/rust-session-manager.cc | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index c948f3d15..cf34e8f47 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -328,6 +328,8 @@ Session::handle_cfg_option (std::string &input)
 bool
 Session::enable_dump (std::string arg)
 {
+  const std::string INTERNAL_DUMP_OPTION_TEXT = "internal";
+
   if (arg.empty ())
     {
       rust_error_at (
@@ -383,21 +385,23 @@ Session::enable_dump (std::string arg)
     {
       options.enable_dump_option (CompileOptions::BIR_DUMP);
     }
-  else if (!arg.compare (0, 8, "internal"))
+  else if (!arg.compare (0, INTERNAL_DUMP_OPTION_TEXT.size (),
+                        INTERNAL_DUMP_OPTION_TEXT))
     {
-      if (arg.size () == 8)
+      if (arg.size () == INTERNAL_DUMP_OPTION_TEXT.size ())
        {
          options.enable_dump_option (CompileOptions::INTERNAL_DUMP);
        }
       else
        {
-         if (arg[8] != ':')
+         if (arg[INTERNAL_DUMP_OPTION_TEXT.size ()] != ':')
            {
-             rust_error_at (UNDEF_LOCATION,
-                            "%qs malformated to specify Node to ignore when "
-                            "dumping internal comment put a "
-                            "%qs then all the Nodes separated by comma",
-                            arg.c_str (), ":");
+             rust_error_at (UNDEF_LOCATION, "bad format for %qs",
+                            arg.c_str ());
+             rust_inform (UNDEF_LOCATION,
+                          "to specify the nodes to ignore when "
+                          "dumping their description put a "
+                          "%<:%> then all the Nodes separated by comma");
              return false;
            }
          handle_excluded_node (arg);
@@ -409,9 +413,9 @@ Session::enable_dump (std::string arg)
       rust_error_at (
        UNDEF_LOCATION,
        "dump option %qs was unrecognised. choose %<lex%>, %<ast-pretty%>, "
-       "%<register_plugins%>, %<injection%>, "
-       "%<expansion%>, %<resolution%>, %<target_options%>, %<hir%>, "
-       "%<hir-pretty%>, or %<all%>",
+       "%<internal[:ignore1,ignore2,...]%>, %<register_plugins%>, "
+       "%<injection%>, %<expansion%>, %<resolution%>, %<target_options%>, "
+       "%<hir%>, %<hir-pretty%>, or %<all%>",
        arg.c_str ());
       return false;
     }
@@ -424,9 +428,9 @@ Session::enable_dump (std::string arg)
 void
 Session::handle_excluded_node (std::string arg)
 {
-  const int size_node_string = 50;
-  std::istringstream blist_str (
-    arg.substr (arg.find (":") + 1, size_node_string));
+  size_t colon = arg.find (":");
+  size_t suffix_size = arg.size () - colon;
+  std::istringstream blist_str (arg.substr (colon + 1, suffix_size));
   std::string token;
   while (std::getline (blist_str, token, ','))
     {
-- 
2.52.0

Reply via email to