diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-07-27 13:11:08 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:56:01 +0100 |
commit | de7e34bdd6c62294831d867188807216e186ed03 (patch) | |
tree | 3099f625a00771e06479bdd144d57c758785243d | |
parent | 1346a7652e8cf70b54f0b12f6844f0c929781c2f (diff) | |
download | gcc-de7e34bdd6c62294831d867188807216e186ed03.zip gcc-de7e34bdd6c62294831d867188807216e186ed03.tar.gz gcc-de7e34bdd6c62294831d867188807216e186ed03.tar.bz2 |
gccrs: proc_macro: Refactor attribute search
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>
-rw-r--r-- | gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc index fc00dcb..c656e76 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc @@ -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. |