@@ -509,14 +509,14 @@ impl ProjectWorkspace {
509
509
build_scripts,
510
510
toolchain : _,
511
511
} => cargo_to_crate_graph (
512
- rustc_cfg. clone ( ) ,
513
- cfg_overrides,
514
512
load_proc_macro,
515
513
load,
514
+ rustc,
516
515
cargo,
517
- build_scripts,
518
516
sysroot. as_ref ( ) ,
519
- rustc,
517
+ rustc_cfg. clone ( ) ,
518
+ cfg_overrides,
519
+ build_scripts,
520
520
) ,
521
521
ProjectWorkspace :: DetachedFiles { files, sysroot, rustc_cfg } => {
522
522
detached_files_to_crate_graph ( rustc_cfg. clone ( ) , load, files, sysroot)
@@ -602,7 +602,7 @@ fn project_json_to_crate_graph(
602
602
for ( from, krate) in project. crates ( ) {
603
603
if let Some ( & from) = crates. get ( & from) {
604
604
if let Some ( ( public_deps, libproc_macro) ) = & sysroot_deps {
605
- public_deps. add ( from , & mut crate_graph) ;
605
+ public_deps. add_to_crate_graph ( & mut crate_graph, from ) ;
606
606
if krate. is_proc_macro {
607
607
if let Some ( proc_macro) = libproc_macro {
608
608
add_dep (
@@ -626,14 +626,14 @@ fn project_json_to_crate_graph(
626
626
}
627
627
628
628
fn cargo_to_crate_graph (
629
- rustc_cfg : Vec < CfgFlag > ,
630
- override_cfg : & CfgOverrides ,
631
629
load_proc_macro : & mut dyn FnMut ( & str , & AbsPath ) -> ProcMacroLoadResult ,
632
630
load : & mut dyn FnMut ( & AbsPath ) -> Option < FileId > ,
631
+ rustc : & Option < CargoWorkspace > ,
633
632
cargo : & CargoWorkspace ,
634
- build_scripts : & WorkspaceBuildScripts ,
635
633
sysroot : Option < & Sysroot > ,
636
- rustc : & Option < CargoWorkspace > ,
634
+ rustc_cfg : Vec < CfgFlag > ,
635
+ override_cfg : & CfgOverrides ,
636
+ build_scripts : & WorkspaceBuildScripts ,
637
637
) -> CrateGraph {
638
638
let _p = profile:: span ( "cargo_to_crate_graph" ) ;
639
639
let mut crate_graph = CrateGraph :: default ( ) ;
@@ -642,13 +642,15 @@ fn cargo_to_crate_graph(
642
642
None => ( SysrootPublicDeps :: default ( ) , None ) ,
643
643
} ;
644
644
645
- let mut cfg_options = CfgOptions :: default ( ) ;
646
- cfg_options. extend ( rustc_cfg) ;
645
+ let cfg_options = {
646
+ let mut cfg_options = CfgOptions :: default ( ) ;
647
+ cfg_options. extend ( rustc_cfg) ;
648
+ cfg_options. insert_atom ( "debug_assertions" . into ( ) ) ;
649
+ cfg_options
650
+ } ;
647
651
648
652
let mut pkg_to_lib_crate = FxHashMap :: default ( ) ;
649
653
650
- cfg_options. insert_atom ( "debug_assertions" . into ( ) ) ;
651
-
652
654
let mut pkg_crates = FxHashMap :: default ( ) ;
653
655
// Does any crate signal to rust-analyzer that they need the rustc_private crates?
654
656
let mut has_private = false ;
@@ -723,7 +725,7 @@ fn cargo_to_crate_graph(
723
725
// Set deps to the core, std and to the lib target of the current package
724
726
for & ( from, kind) in pkg_crates. get ( & pkg) . into_iter ( ) . flatten ( ) {
725
727
// Add sysroot deps first so that a lib target named `core` etc. can overwrite them.
726
- public_deps. add ( from , & mut crate_graph) ;
728
+ public_deps. add_to_crate_graph ( & mut crate_graph, from ) ;
727
729
728
730
if let Some ( ( to, name) ) = lib_tgt. clone ( ) {
729
731
if to != from && kind != TargetKind :: BuildScript {
@@ -767,15 +769,16 @@ fn cargo_to_crate_graph(
767
769
if let Some ( rustc_workspace) = rustc {
768
770
handle_rustc_crates (
769
771
& mut crate_graph,
770
- rustc_workspace ,
772
+ & mut pkg_to_lib_crate ,
771
773
load,
772
- & cfg_options,
773
- override_cfg,
774
774
load_proc_macro,
775
- & mut pkg_to_lib_crate,
776
- & public_deps,
775
+ rustc_workspace,
777
776
cargo,
777
+ & public_deps,
778
+ libproc_macro,
778
779
& pkg_crates,
780
+ & cfg_options,
781
+ override_cfg,
779
782
build_scripts,
780
783
) ;
781
784
}
@@ -825,28 +828,29 @@ fn detached_files_to_crate_graph(
825
828
} ,
826
829
) ;
827
830
828
- public_deps. add ( detached_file_crate , & mut crate_graph) ;
831
+ public_deps. add_to_crate_graph ( & mut crate_graph, detached_file_crate ) ;
829
832
}
830
833
crate_graph
831
834
}
832
835
833
836
fn handle_rustc_crates (
834
837
crate_graph : & mut CrateGraph ,
835
- rustc_workspace : & CargoWorkspace ,
838
+ pkg_to_lib_crate : & mut FxHashMap < Package , CrateId > ,
836
839
load : & mut dyn FnMut ( & AbsPath ) -> Option < FileId > ,
837
- cfg_options : & CfgOptions ,
838
- override_cfg : & CfgOverrides ,
839
840
load_proc_macro : & mut dyn FnMut ( & str , & AbsPath ) -> ProcMacroLoadResult ,
840
- pkg_to_lib_crate : & mut FxHashMap < Package , CrateId > ,
841
- public_deps : & SysrootPublicDeps ,
841
+ rustc_workspace : & CargoWorkspace ,
842
842
cargo : & CargoWorkspace ,
843
+ public_deps : & SysrootPublicDeps ,
844
+ libproc_macro : Option < CrateId > ,
843
845
pkg_crates : & FxHashMap < Package , Vec < ( CrateId , TargetKind ) > > ,
846
+ cfg_options : & CfgOptions ,
847
+ override_cfg : & CfgOverrides ,
844
848
build_scripts : & WorkspaceBuildScripts ,
845
849
) {
846
850
let mut rustc_pkg_crates = FxHashMap :: default ( ) ;
847
851
// The root package of the rustc-dev component is rustc_driver, so we match that
848
852
let root_pkg =
849
- rustc_workspace. packages ( ) . find ( |package| rustc_workspace[ * package] . name == "rustc_driver" ) ;
853
+ rustc_workspace. packages ( ) . find ( |& package| rustc_workspace[ package] . name == "rustc_driver" ) ;
850
854
// The rustc workspace might be incomplete (such as if rustc-dev is not
851
855
// installed for the current toolchain) and `rustc_source` is set to discover.
852
856
if let Some ( root_pkg) = root_pkg {
@@ -901,7 +905,16 @@ fn handle_rustc_crates(
901
905
) ;
902
906
pkg_to_lib_crate. insert ( pkg, crate_id) ;
903
907
// Add dependencies on core / std / alloc for this crate
904
- public_deps. add ( crate_id, crate_graph) ;
908
+ public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
909
+ if let Some ( proc_macro) = libproc_macro {
910
+ add_dep_with_prelude (
911
+ crate_graph,
912
+ crate_id,
913
+ CrateName :: new ( "proc_macro" ) . unwrap ( ) ,
914
+ proc_macro,
915
+ rustc_workspace[ tgt] . is_proc_macro ,
916
+ ) ;
917
+ }
905
918
rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
906
919
}
907
920
}
@@ -1009,7 +1022,7 @@ struct SysrootPublicDeps {
1009
1022
1010
1023
impl SysrootPublicDeps {
1011
1024
/// Makes `from` depend on the public sysroot crates.
1012
- fn add ( & self , from : CrateId , crate_graph : & mut CrateGraph ) {
1025
+ fn add_to_crate_graph ( & self , crate_graph : & mut CrateGraph , from : CrateId ) {
1013
1026
for ( name, krate, prelude) in & self . deps {
1014
1027
add_dep_with_prelude ( crate_graph, from, name. clone ( ) , * krate, * prelude) ;
1015
1028
}
0 commit comments