mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 20:09:01 +00:00 
			
		
		
		
	Drop rustc workspace loading error, if we don't needs its sources
This commit is contained in:
		
							parent
							
								
									ad3a2d7280
								
							
						
					
					
						commit
						aee96c7f17
					
				
					 2 changed files with 28 additions and 10 deletions
				
			
		|  | @ -48,6 +48,7 @@ pub struct CargoWorkspace { | ||||||
|     is_sysroot: bool, |     is_sysroot: bool, | ||||||
|     /// Environment variables set in the `.cargo/config` file.
 |     /// Environment variables set in the `.cargo/config` file.
 | ||||||
|     config_env: Env, |     config_env: Env, | ||||||
|  |     requires_rustc_private: bool, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl ops::Index<Package> for CargoWorkspace { | impl ops::Index<Package> for CargoWorkspace { | ||||||
|  | @ -513,6 +514,7 @@ impl CargoWorkspace { | ||||||
|         let workspace_root = AbsPathBuf::assert(meta.workspace_root); |         let workspace_root = AbsPathBuf::assert(meta.workspace_root); | ||||||
|         let target_directory = AbsPathBuf::assert(meta.target_directory); |         let target_directory = AbsPathBuf::assert(meta.target_directory); | ||||||
|         let mut is_virtual_workspace = true; |         let mut is_virtual_workspace = true; | ||||||
|  |         let mut requires_rustc_private = false; | ||||||
| 
 | 
 | ||||||
|         meta.packages.sort_by(|a, b| a.id.cmp(&b.id)); |         meta.packages.sort_by(|a, b| a.id.cmp(&b.id)); | ||||||
|         for meta_pkg in meta.packages { |         for meta_pkg in meta.packages { | ||||||
|  | @ -577,6 +579,7 @@ impl CargoWorkspace { | ||||||
|                 metadata: meta.rust_analyzer.unwrap_or_default(), |                 metadata: meta.rust_analyzer.unwrap_or_default(), | ||||||
|             }); |             }); | ||||||
|             let pkg_data = &mut packages[pkg]; |             let pkg_data = &mut packages[pkg]; | ||||||
|  |             requires_rustc_private |= pkg_data.metadata.rustc_private; | ||||||
|             pkg_by_id.insert(id, pkg); |             pkg_by_id.insert(id, pkg); | ||||||
|             for meta_tgt in meta_targets { |             for meta_tgt in meta_targets { | ||||||
|                 let cargo_metadata::Target { name, kind, required_features, src_path, .. } = |                 let cargo_metadata::Target { name, kind, required_features, src_path, .. } = | ||||||
|  | @ -626,6 +629,7 @@ impl CargoWorkspace { | ||||||
|             target_directory, |             target_directory, | ||||||
|             manifest_path: ws_manifest_path, |             manifest_path: ws_manifest_path, | ||||||
|             is_virtual_workspace, |             is_virtual_workspace, | ||||||
|  |             requires_rustc_private, | ||||||
|             is_sysroot, |             is_sysroot, | ||||||
|             config_env: cargo_config_env, |             config_env: cargo_config_env, | ||||||
|         } |         } | ||||||
|  | @ -724,4 +728,8 @@ impl CargoWorkspace { | ||||||
|     pub fn is_sysroot(&self) -> bool { |     pub fn is_sysroot(&self) -> bool { | ||||||
|         self.is_sysroot |         self.is_sysroot | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     pub fn requires_rustc_private(&self) -> bool { | ||||||
|  |         self.requires_rustc_private | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -408,8 +408,14 @@ impl ProjectWorkspace { | ||||||
|             )) |             )) | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         let (rustc_cfg, data_layout, rustc, loaded_sysroot, cargo_metadata, cargo_config_extra_env) = |         let ( | ||||||
|             match join { |             rustc_cfg, | ||||||
|  |             data_layout, | ||||||
|  |             mut rustc, | ||||||
|  |             loaded_sysroot, | ||||||
|  |             cargo_metadata, | ||||||
|  |             cargo_config_extra_env, | ||||||
|  |         ) = match join { | ||||||
|             Ok(it) => it, |             Ok(it) => it, | ||||||
|             Err(e) => std::panic::resume_unwind(e), |             Err(e) => std::panic::resume_unwind(e), | ||||||
|         }; |         }; | ||||||
|  | @ -425,6 +431,14 @@ impl ProjectWorkspace { | ||||||
|             sysroot.set_workspace(loaded_sysroot); |             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 { |         Ok(ProjectWorkspace { | ||||||
|             kind: ProjectWorkspaceKind::Cargo { |             kind: ProjectWorkspaceKind::Cargo { | ||||||
|                 cargo, |                 cargo, | ||||||
|  | @ -1208,14 +1222,10 @@ fn cargo_to_crate_graph( | ||||||
|     // Mapping of a package to its library target
 |     // Mapping of a package to its library target
 | ||||||
|     let mut pkg_to_lib_crate = FxHashMap::default(); |     let mut pkg_to_lib_crate = FxHashMap::default(); | ||||||
|     let mut pkg_crates = 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()); |     let workspace_proc_macro_cwd = Arc::new(cargo.workspace_root().to_path_buf()); | ||||||
| 
 | 
 | ||||||
|     // Next, create crates for each package, target pair
 |     // Next, create crates for each package, target pair
 | ||||||
|     for pkg in cargo.packages() { |     for pkg in cargo.packages() { | ||||||
|         has_private |= cargo[pkg].metadata.rustc_private; |  | ||||||
| 
 |  | ||||||
|         let cfg_options = { |         let cfg_options = { | ||||||
|             let mut cfg_options = cfg_options.clone(); |             let mut cfg_options = cfg_options.clone(); | ||||||
| 
 | 
 | ||||||
|  | @ -1360,7 +1370,7 @@ fn cargo_to_crate_graph( | ||||||
|         add_dep(crate_graph, from, name, to); |         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
 |         // 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
 |         // and create dependencies on them for the crates which opt-in to that
 | ||||||
|         if let Some((rustc_workspace, rustc_build_scripts)) = rustc { |         if let Some((rustc_workspace, rustc_build_scripts)) = rustc { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Wirth
						Lukas Wirth