]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: proc_macro: Refactor attribute search
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 27 Jul 2023 11:11:08 +0000 (13:11 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:56:01 +0000 (18:56 +0100)
Refactor attribute search with early return. Also fix the optional
building an object with it's default empty constructor by explicitely
using tl::null_opt.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Refactor the function to be safer and more efficient.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc

index fc00dcbbae6d419c63ca5938b778ffdc33fa63b3..c656e761dcccb88650f2bde0dd9d417b6d2482ad 100644 (file)
@@ -37,8 +37,6 @@ PrivacyReporter::PrivacyReporter (
 static tl::optional<std::string>
 find_proc_macro_attribute (const AST::AttrVec &outer_attrs)
 {
-  tl::optional<std::string> result;
-
   for (auto &a : outer_attrs)
     {
       auto &segments = a.get_path ().get_segments ();
@@ -47,10 +45,10 @@ find_proc_macro_attribute (const AST::AttrVec &outer_attrs)
       auto name = segments.at (0).get_segment_name ();
       if (name == "proc_macro" || name == "proc_macro_attribute"
          || name == "proc_macro_derive")
-       result = {name};
+       return name;
     }
 
-  return result;
+  return tl::nullopt;
 }
 
 // Common check on crate items when dealing with 'proc-macro' crate type.