about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorLukas Wirth <me@lukaswirth.dev>2025-06-25 10:20:30 +0000
committerGitHub <noreply@github.com>2025-06-25 10:20:30 +0000
commitcd4100da477d3b597ec6677a5eeaac219a667e9b (patch)
treed5129490c5011524c658d1403bd598c418db4e91 /src/tools
parentca062eb7d428f2ad5f2446d938367986eda76c75 (diff)
parent7d6f77f8be42ee5c4d921cc52f885ddc0b566974 (diff)
downloadrust-cd4100da477d3b597ec6677a5eeaac219a667e9b.tar.gz
rust-cd4100da477d3b597ec6677a5eeaac219a667e9b.zip
Merge pull request #20092 from Veykril/push-kollxvpyknqs
Drop rustc workspace loading error, if we don't needs its sources
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs8
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/workspace.rs30
2 files changed, 28 insertions, 10 deletions
diff --git a/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs b/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
index 58507418e4d..4bacc904174 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
@@ -48,6 +48,7 @@ pub struct CargoWorkspace {
     is_sysroot: bool,
     /// Environment variables set in the `.cargo/config` file.
     config_env: Env,
+    requires_rustc_private: bool,
 }
 
 impl ops::Index<Package> for CargoWorkspace {
@@ -513,6 +514,7 @@ impl CargoWorkspace {
         let workspace_root = AbsPathBuf::assert(meta.workspace_root);
         let target_directory = AbsPathBuf::assert(meta.target_directory);
         let mut is_virtual_workspace = true;
+        let mut requires_rustc_private = false;
 
         meta.packages.sort_by(|a, b| a.id.cmp(&b.id));
         for meta_pkg in meta.packages {
@@ -577,6 +579,7 @@ impl CargoWorkspace {
                 metadata: meta.rust_analyzer.unwrap_or_default(),
             });
             let pkg_data = &mut packages[pkg];
+            requires_rustc_private |= pkg_data.metadata.rustc_private;
             pkg_by_id.insert(id, pkg);
             for meta_tgt in meta_targets {
                 let cargo_metadata::Target { name, kind, required_features, src_path, .. } =
@@ -626,6 +629,7 @@ impl CargoWorkspace {
             target_directory,
             manifest_path: ws_manifest_path,
             is_virtual_workspace,
+            requires_rustc_private,
             is_sysroot,
             config_env: cargo_config_env,
         }
@@ -724,4 +728,8 @@ impl CargoWorkspace {
     pub fn is_sysroot(&self) -> bool {
         self.is_sysroot
     }
+
+    pub fn requires_rustc_private(&self) -> bool {
+        self.requires_rustc_private
+    }
 }
diff --git a/src/tools/rust-analyzer/crates/project-model/src/workspace.rs b/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
index 079fc3b3f65..81ba5d043e2 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
@@ -408,11 +408,17 @@ impl ProjectWorkspace {
             ))
         });
 
-        let (rustc_cfg, data_layout, rustc, loaded_sysroot, cargo_metadata, cargo_config_extra_env) =
-            match join {
-                Ok(it) => it,
-                Err(e) => std::panic::resume_unwind(e),
-            };
+        let (
+            rustc_cfg,
+            data_layout,
+            mut rustc,
+            loaded_sysroot,
+            cargo_metadata,
+            cargo_config_extra_env,
+        ) = match join {
+            Ok(it) => it,
+            Err(e) => std::panic::resume_unwind(e),
+        };
 
         let (meta, error) = cargo_metadata.with_context(|| {
             format!(
@@ -425,6 +431,14 @@ impl ProjectWorkspace {
             sysroot.set_workspace(loaded_sysroot);
         }
 
+        if !cargo.requires_rustc_private() {
+            if let Err(e) = &mut rustc {
+                // We don't need the rustc sources here,
+                // so just discard the error.
+                _ = e.take();
+            }
+        }
+
         Ok(ProjectWorkspace {
             kind: ProjectWorkspaceKind::Cargo {
                 cargo,
@@ -1208,14 +1222,10 @@ fn cargo_to_crate_graph(
     // Mapping of a package to its library target
     let mut pkg_to_lib_crate = FxHashMap::default();
     let mut pkg_crates = FxHashMap::default();
-    // Does any crate signal to rust-analyzer that they need the rustc_private crates?
-    let mut has_private = false;
     let workspace_proc_macro_cwd = Arc::new(cargo.workspace_root().to_path_buf());
 
     // Next, create crates for each package, target pair
     for pkg in cargo.packages() {
-        has_private |= cargo[pkg].metadata.rustc_private;
-
         let cfg_options = {
             let mut cfg_options = cfg_options.clone();
 
@@ -1360,7 +1370,7 @@ fn cargo_to_crate_graph(
         add_dep(crate_graph, from, name, to);
     }
 
-    if has_private {
+    if cargo.requires_rustc_private() {
         // If the user provided a path to rustc sources, we add all the rustc_private crates
         // and create dependencies on them for the crates which opt-in to that
         if let Some((rustc_workspace, rustc_build_scripts)) = rustc {