Move RustValues::transitive_libs_ to Target::rust_transitive_libs_

This field is used by all targets, even if it is only useful to
generate the build commands for final Rust targets.

This prepares for moving Target::rust_values_ into an
std::unique_pointer<> in a future CL.

Change-Id: I1154ac1da5980b80440ad5f99602c1149bc97c20
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/12400
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Petr Hosek <phosek@google.com>
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: David Turner <digit@google.com>
diff --git a/src/gn/ninja_c_binary_target_writer.cc b/src/gn/ninja_c_binary_target_writer.cc
index d9c3ad2..376c943 100644
--- a/src/gn/ninja_c_binary_target_writer.cc
+++ b/src/gn/ninja_c_binary_target_writer.cc
@@ -780,8 +780,7 @@
   // entire tree of transitive rlibs.
   std::vector<OutputFile> transitive_rustlibs;
   if (target_->IsFinal()) {
-    for (const auto* dep :
-         target_->rust_values().transitive_libs().GetOrdered()) {
+    for (const auto* dep : target_->rust_transitive_libs().GetOrdered()) {
       if (dep->output_type() == Target::RUST_LIBRARY) {
         transitive_rustlibs.push_back(dep->dependency_output_file());
         implicit_deps.push_back(dep->dependency_output_file());
diff --git a/src/gn/ninja_rust_binary_target_writer.cc b/src/gn/ninja_rust_binary_target_writer.cc
index 140fe09..d894681 100644
--- a/src/gn/ninja_rust_binary_target_writer.cc
+++ b/src/gn/ninja_rust_binary_target_writer.cc
@@ -178,8 +178,7 @@
 
   // Bubble up the full list of transitive rlib dependencies.
   std::vector<OutputFile> transitive_rustlibs;
-  for (const auto* dep :
-       target_->rust_values().transitive_libs().GetOrdered()) {
+  for (const auto* dep : target_->rust_transitive_libs().GetOrdered()) {
     if (dep->source_types_used().RustSourceUsed()) {
       transitive_rustlibs.push_back(dep->dependency_output_file());
     }
diff --git a/src/gn/rust_values.h b/src/gn/rust_values.h
index 3185340..d201014 100644
--- a/src/gn/rust_values.h
+++ b/src/gn/rust_values.h
@@ -74,16 +74,11 @@
   }
   std::map<Label, std::string>& aliased_deps() { return aliased_deps_; }
 
-  // Transitive closure of libraries that are depended on by this target
-  InheritedLibraries& transitive_libs() { return rust_libs_; }
-  const InheritedLibraries& transitive_libs() const { return rust_libs_; }
-
  private:
   std::string crate_name_;
   SourceFile crate_root_;
   CrateType crate_type_ = CRATE_AUTO;
   std::map<Label, std::string> aliased_deps_;
-  InheritedLibraries rust_libs_;
 
   RustValues(const RustValues&) = delete;
   RustValues& operator=(const RustValues&) = delete;
diff --git a/src/gn/target.cc b/src/gn/target.cc
index 7071357..d9c02d3 100644
--- a/src/gn/target.cc
+++ b/src/gn/target.cc
@@ -655,13 +655,13 @@
   if (dep->output_type() == STATIC_LIBRARY ||
       dep->output_type() == SHARED_LIBRARY ||
       dep->output_type() == RUST_LIBRARY) {
-    rust_values().transitive_libs().Append(dep, is_public);
+    rust_transitive_libs_.Append(dep, is_public);
 
     // Propagate public dependent libraries.
     for (const auto& transitive :
-         dep->rust_values().transitive_libs().GetOrderedAndPublicFlag()) {
+         dep->rust_transitive_libs_.GetOrderedAndPublicFlag()) {
       if (transitive.second) {
-        rust_values().transitive_libs().Append(transitive.first, is_public);
+        rust_transitive_libs_.Append(transitive.first, is_public);
       }
     }
   }
@@ -670,13 +670,13 @@
   // handled the same way, whether static or dynamic.
   if (dep->output_type() == RUST_LIBRARY ||
       RustValues::InferredCrateType(dep) == RustValues::CRATE_DYLIB) {
-    rust_values().transitive_libs().AppendInherited(
-        dep->rust_values().transitive_libs(), is_public);
+    rust_transitive_libs_.AppendInherited(dep->rust_transitive_libs_,
+                                          is_public);
 
     // If there is a transitive dependency that is not a rust library, place it
     // in the normal location
     for (const auto& inherited :
-         rust_values().transitive_libs().GetOrderedAndPublicFlag()) {
+         rust_transitive_libs_.GetOrderedAndPublicFlag()) {
       if (!RustValues::IsRustLibrary(inherited.first)) {
         inherited_libraries_.Append(inherited.first, inherited.second);
       }
@@ -685,7 +685,7 @@
     // We will need to specify the path to find a procedural macro,
     // but have no need to specify the paths to find its dependencies
     // as the procedural macro is now a complete .so.
-    rust_values().transitive_libs().Append(dep, is_public);
+    rust_transitive_libs_.Append(dep, is_public);
   } else if (dep->output_type() == SHARED_LIBRARY) {
     // Shared library dependendencies are inherited across public shared
     // library boundaries.
@@ -713,8 +713,8 @@
     // The current target isn't linked, so propagate linked deps and
     // libraries up the dependency tree.
     inherited_libraries_.AppendInherited(dep->inherited_libraries(), is_public);
-    rust_values().transitive_libs().AppendInherited(
-        dep->rust_values().transitive_libs(), is_public);
+    rust_transitive_libs_.AppendInherited(dep->rust_transitive_libs_,
+                                          is_public);
   } else if (dep->complete_static_lib()) {
     // Inherit only final targets through _complete_ static libraries.
     //
diff --git a/src/gn/target.h b/src/gn/target.h
index 293d53c..fec9731 100644
--- a/src/gn/target.h
+++ b/src/gn/target.h
@@ -284,6 +284,12 @@
   RustValues& rust_values() { return rust_values_; }
   const RustValues& rust_values() const { return rust_values_; }
 
+  // Transitive closure of libraries that are depended on by this target
+  InheritedLibraries& rust_transitive_libs() { return rust_transitive_libs_; }
+  const InheritedLibraries& rust_transitive_libs() const {
+    return rust_transitive_libs_;
+  }
+
   const UniqueVector<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; }
   const UniqueVector<LibFile>& all_libs() const { return all_libs_; }
 
@@ -485,6 +491,9 @@
   // Used for Rust targets.
   RustValues rust_values_;
 
+  // Used by all targets, only useful to generate Rust targets though.
+  InheritedLibraries rust_transitive_libs_;
+
   // User for Swift targets.
   SwiftValues swift_values_;