@@ -24,7 +24,7 @@ use crate::{
24
24
rustc_cfg,
25
25
sysroot:: SysrootCrate ,
26
26
target_data_layout, utf8_stdout, CargoConfig , CargoWorkspace , InvocationStrategy , ManifestPath ,
27
- Package , ProjectJson , ProjectManifest , Sysroot , TargetKind , WorkspaceBuildScripts ,
27
+ Package , ProjectJson , ProjectManifest , Sysroot , TargetData , TargetKind , WorkspaceBuildScripts ,
28
28
} ;
29
29
30
30
/// A set of cfg-overrides per crate.
@@ -900,7 +900,24 @@ fn cargo_to_crate_graph(
900
900
// https://github.com/rust-lang/rust-analyzer/issues/11300
901
901
continue ;
902
902
}
903
- let Some ( file_id) = load ( & cargo[ tgt] . root ) else { continue } ;
903
+ let & TargetData { ref name, kind, is_proc_macro, ref root, .. } = & cargo[ tgt] ;
904
+
905
+ if kind == TargetKind :: Lib
906
+ && sysroot. map_or ( false , |sysroot| root. starts_with ( sysroot. src_root ( ) ) )
907
+ {
908
+ if let Some ( & ( _, crate_id, _) ) =
909
+ public_deps. deps . iter ( ) . find ( |( dep_name, ..) | dep_name. as_smol_str ( ) == name)
910
+ {
911
+ pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
912
+
913
+ lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
914
+ pkg_to_lib_crate. insert ( pkg, crate_id) ;
915
+ // sysroot is inside the workspace, prevent the sysroot crates from being duplicated here
916
+ continue ;
917
+ }
918
+ }
919
+
920
+ let Some ( file_id) = load ( root) else { continue } ;
904
921
905
922
let crate_id = add_target_crate_root (
906
923
crate_graph,
@@ -909,23 +926,23 @@ fn cargo_to_crate_graph(
909
926
build_scripts. get_output ( pkg) ,
910
927
cfg_options. clone ( ) ,
911
928
file_id,
912
- & cargo [ tgt ] . name ,
913
- cargo [ tgt ] . is_proc_macro ,
929
+ name,
930
+ is_proc_macro,
914
931
target_layout. clone ( ) ,
915
932
false ,
916
933
channel,
917
934
) ;
918
- if cargo [ tgt ] . kind == TargetKind :: Lib {
919
- lib_tgt = Some ( ( crate_id, cargo [ tgt ] . name . clone ( ) ) ) ;
935
+ if kind == TargetKind :: Lib {
936
+ lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
920
937
pkg_to_lib_crate. insert ( pkg, crate_id) ;
921
938
}
922
939
// Even crates that don't set proc-macro = true are allowed to depend on proc_macro
923
940
// (just none of the APIs work when called outside of a proc macro).
924
941
if let Some ( proc_macro) = libproc_macro {
925
- add_proc_macro_dep ( crate_graph, crate_id, proc_macro, cargo [ tgt ] . is_proc_macro ) ;
942
+ add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
926
943
}
927
944
928
- pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, cargo [ tgt ] . kind ) ) ;
945
+ pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
929
946
}
930
947
931
948
// Set deps to the core, std and to the lib target of the current package
0 commit comments