@@ -408,11 +408,17 @@ impl ProjectWorkspace {
408408 ) )
409409 } ) ;
410410
411- let ( rustc_cfg, data_layout, rustc, loaded_sysroot, cargo_metadata, cargo_config_extra_env) =
412- match join {
413- Ok ( it) => it,
414- Err ( e) => std:: panic:: resume_unwind ( e) ,
415- } ;
411+ let (
412+ rustc_cfg,
413+ data_layout,
414+ mut rustc,
415+ loaded_sysroot,
416+ cargo_metadata,
417+ cargo_config_extra_env,
418+ ) = match join {
419+ Ok ( it) => it,
420+ Err ( e) => std:: panic:: resume_unwind ( e) ,
421+ } ;
416422
417423 let ( meta, error) = cargo_metadata. with_context ( || {
418424 format ! (
@@ -425,6 +431,14 @@ impl ProjectWorkspace {
425431 sysroot. set_workspace ( loaded_sysroot) ;
426432 }
427433
434+ if !cargo. requires_rustc_private ( ) {
435+ if let Err ( e) = & mut rustc {
436+ // We don't need the rustc sources here,
437+ // so just discard the error.
438+ _ = e. take ( ) ;
439+ }
440+ }
441+
428442 Ok ( ProjectWorkspace {
429443 kind : ProjectWorkspaceKind :: Cargo {
430444 cargo,
@@ -1208,14 +1222,10 @@ fn cargo_to_crate_graph(
12081222 // Mapping of a package to its library target
12091223 let mut pkg_to_lib_crate = FxHashMap :: default ( ) ;
12101224 let mut pkg_crates = FxHashMap :: default ( ) ;
1211- // Does any crate signal to rust-analyzer that they need the rustc_private crates?
1212- let mut has_private = false ;
12131225 let workspace_proc_macro_cwd = Arc :: new ( cargo. workspace_root ( ) . to_path_buf ( ) ) ;
12141226
12151227 // Next, create crates for each package, target pair
12161228 for pkg in cargo. packages ( ) {
1217- has_private |= cargo[ pkg] . metadata . rustc_private ;
1218-
12191229 let cfg_options = {
12201230 let mut cfg_options = cfg_options. clone ( ) ;
12211231
@@ -1360,7 +1370,7 @@ fn cargo_to_crate_graph(
13601370 add_dep ( crate_graph, from, name, to) ;
13611371 }
13621372
1363- if has_private {
1373+ if cargo . requires_rustc_private ( ) {
13641374 // If the user provided a path to rustc sources, we add all the rustc_private crates
13651375 // and create dependencies on them for the crates which opt-in to that
13661376 if let Some ( ( rustc_workspace, rustc_build_scripts) ) = rustc {
0 commit comments