Skip to content

Commit

Permalink
proc_macro: Refactor attribute search
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
P-E-P committed Jul 27, 2023
1 parent f925f2f commit ddce1d9
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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.
Expand Down

0 comments on commit ddce1d9

Please sign in to comment.