@@ -408,11 +408,17 @@ impl ProjectWorkspace {
408
408
) )
409
409
} ) ;
410
410
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
+ } ;
416
422
417
423
let ( meta, error) = cargo_metadata. with_context ( || {
418
424
format ! (
@@ -425,6 +431,14 @@ impl ProjectWorkspace {
425
431
sysroot. set_workspace ( loaded_sysroot) ;
426
432
}
427
433
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
+
428
442
Ok ( ProjectWorkspace {
429
443
kind : ProjectWorkspaceKind :: Cargo {
430
444
cargo,
@@ -1208,14 +1222,10 @@ fn cargo_to_crate_graph(
1208
1222
// Mapping of a package to its library target
1209
1223
let mut pkg_to_lib_crate = FxHashMap :: default ( ) ;
1210
1224
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 ;
1213
1225
let workspace_proc_macro_cwd = Arc :: new ( cargo. workspace_root ( ) . to_path_buf ( ) ) ;
1214
1226
1215
1227
// Next, create crates for each package, target pair
1216
1228
for pkg in cargo. packages ( ) {
1217
- has_private |= cargo[ pkg] . metadata . rustc_private ;
1218
-
1219
1229
let cfg_options = {
1220
1230
let mut cfg_options = cfg_options. clone ( ) ;
1221
1231
@@ -1360,7 +1370,7 @@ fn cargo_to_crate_graph(
1360
1370
add_dep ( crate_graph, from, name, to) ;
1361
1371
}
1362
1372
1363
- if has_private {
1373
+ if cargo . requires_rustc_private ( ) {
1364
1374
// If the user provided a path to rustc sources, we add all the rustc_private crates
1365
1375
// and create dependencies on them for the crates which opt-in to that
1366
1376
if let Some ( ( rustc_workspace, rustc_build_scripts) ) = rustc {
0 commit comments