diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-07-27 13:11:08 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2023-07-27 12:24:54 +0000 |
commit | ddce1d9e9e783af7e14a99f112c86d006ca0ee02 (patch) | |
tree | 5b0cb81b279ca7a4035ca967b27e9ce9431a0f00 /gcc | |
parent | f925f2f094da19369a77ce88ffa378316d788285 (diff) | |
download | gcc-ddce1d9e9e783af7e14a99f112c86d006ca0ee02.zip gcc-ddce1d9e9e783af7e14a99f112c86d006ca0ee02.tar.gz gcc-ddce1d9e9e783af7e14a99f112c86d006ca0ee02.tar.bz2 |
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>
Diffstat (limited to 'gcc')
-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 7845962..02d5153 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. |