From: Owen Avery <[email protected]>

Removes some unnecessary AST node copying.

gcc/rust/ChangeLog:

        * checks/errors/privacy/rust-visibility-resolver.cc
        (VisibilityResolver::resolve_module_path): Refer to crate
        by reference.
        * checks/errors/rust-builtin-attribute-checker.h
        (BuiltinAttributeChecker::default_outer_attribute_check): Accept
        item parameter by reference.
        * parse/rust-parse-impl.hxx (Parser::parse_vis_item): Avoid
        unnecessary copy of visibility.
        * rust-session-manager.cc (has_attribute): Accept crate
        parameter by reference.

Signed-off-by: Owen Avery <[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/beb9dd6d95ce73600fba6f986a55741b6b1a12d7

The commit has NOT been mentioned in any issue.

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

 gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc | 2 +-
 gcc/rust/checks/errors/rust-builtin-attribute-checker.h    | 2 +-
 gcc/rust/parse/rust-parse-impl.hxx                         | 2 +-
 gcc/rust/rust-session-manager.cc                           | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc 
b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
index d91a2c7d9..5433cab5a 100644
--- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
+++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
@@ -82,7 +82,7 @@ VisibilityResolver::resolve_module_path (const 
HIR::SimplePath &restriction,
   rust_assert (hid.has_value ());
   auto ref = hid.value ();
 
-  auto crate
+  auto &crate
     = mappings.crate.get_ast_crate (mappings.crate.get_current_crate ());
 
   // we may be dealing with pub(crate)
diff --git a/gcc/rust/checks/errors/rust-builtin-attribute-checker.h 
b/gcc/rust/checks/errors/rust-builtin-attribute-checker.h
index e0564f2a4..b53678b80 100644
--- a/gcc/rust/checks/errors/rust-builtin-attribute-checker.h
+++ b/gcc/rust/checks/errors/rust-builtin-attribute-checker.h
@@ -43,7 +43,7 @@ class BuiltinAttributeChecker : public AST::DefaultASTVisitor
 {
   using AST::DefaultASTVisitor::visit;
 
-  template <class I> void default_outer_attribute_check (I item)
+  template <class I> void default_outer_attribute_check (I &item)
   {
     for (auto &attr : item.get_outer_attrs ())
       check_valid_attribute_for_item (attr, item);
diff --git a/gcc/rust/parse/rust-parse-impl.hxx 
b/gcc/rust/parse/rust-parse-impl.hxx
index a04dd51d2..3f8f964e4 100644
--- a/gcc/rust/parse/rust-parse-impl.hxx
+++ b/gcc/rust/parse/rust-parse-impl.hxx
@@ -487,7 +487,7 @@ Parser<ManagedTokenSource>::parse_vis_item (AST::AttrVec 
outer_attrs)
   auto vis_res = parse_visibility ();
   if (!vis_res)
     return nullptr;
-  auto vis = vis_res.value ();
+  auto vis = std::move (vis_res.value ());
 
   // select VisItem to create depending on keyword
   const_TokenPtr t = lexer.peek_token ();
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index f7b663cae..85b0865a3 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -168,7 +168,7 @@ validate_crate_name (const std::string &crate_name, Error 
&error)
 }
 
 static bool
-has_attribute (AST::Crate crate, std::string attribute)
+has_attribute (AST::Crate &crate, std::string attribute)
 {
   auto &crate_attrs = crate.get_inner_attrs ();
   auto has_attr = [&attribute] (AST::Attribute &attr) {

base-commit: 6a45b39d3e54d1a8222c659759c34a39cd4f2dfc
-- 
2.56.1

Reply via email to