@@ -548,8 +548,7 @@ fn cargo_to_crate_graph(
548
548
let mut has_private = false ;
549
549
// Next, create crates for each package, target pair
550
550
for pkg in cargo. packages ( ) {
551
- let mut cfg_options = & cfg_options;
552
- let mut replaced_cfg_options;
551
+ let mut cfg_options = cfg_options. clone ( ) ;
553
552
554
553
let overrides = match override_cfg {
555
554
CfgOverrides :: Wildcard ( cfg_diff) => Some ( cfg_diff) ,
@@ -558,9 +557,7 @@ fn cargo_to_crate_graph(
558
557
559
558
// Add test cfg for local crates
560
559
if cargo[ pkg] . is_local {
561
- replaced_cfg_options = cfg_options. clone ( ) ;
562
- replaced_cfg_options. insert_atom ( "test" . into ( ) ) ;
563
- cfg_options = & replaced_cfg_options;
560
+ cfg_options. insert_atom ( "test" . into ( ) ) ;
564
561
}
565
562
566
563
if let Some ( overrides) = overrides {
@@ -571,9 +568,7 @@ fn cargo_to_crate_graph(
571
568
// A more ideal solution might be to reanalyze crates based on where the cursor is and
572
569
// figure out the set of cfgs that would have to apply to make it active.
573
570
574
- replaced_cfg_options = cfg_options. clone ( ) ;
575
- replaced_cfg_options. apply_diff ( overrides. clone ( ) ) ;
576
- cfg_options = & replaced_cfg_options;
571
+ cfg_options. apply_diff ( overrides. clone ( ) ) ;
577
572
} ;
578
573
579
574
has_private |= cargo[ pkg] . metadata . rustc_private ;
@@ -593,7 +588,7 @@ fn cargo_to_crate_graph(
593
588
& mut crate_graph,
594
589
& cargo[ pkg] ,
595
590
build_scripts. get_output ( pkg) ,
596
- cfg_options,
591
+ cfg_options. clone ( ) ,
597
592
& mut |path| load_proc_macro ( & cargo[ tgt] . name , path) ,
598
593
file_id,
599
594
& cargo[ tgt] . name ,
@@ -758,8 +753,7 @@ fn handle_rustc_crates(
758
753
queue. push_back ( dep. pkg ) ;
759
754
}
760
755
761
- let mut cfg_options = cfg_options;
762
- let mut replaced_cfg_options;
756
+ let mut cfg_options = cfg_options. clone ( ) ;
763
757
764
758
let overrides = match override_cfg {
765
759
CfgOverrides :: Wildcard ( cfg_diff) => Some ( cfg_diff) ,
@@ -776,9 +770,7 @@ fn handle_rustc_crates(
776
770
// A more ideal solution might be to reanalyze crates based on where the cursor is and
777
771
// figure out the set of cfgs that would have to apply to make it active.
778
772
779
- replaced_cfg_options = cfg_options. clone ( ) ;
780
- replaced_cfg_options. apply_diff ( overrides. clone ( ) ) ;
781
- cfg_options = & replaced_cfg_options;
773
+ cfg_options. apply_diff ( overrides. clone ( ) ) ;
782
774
} ;
783
775
784
776
for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
@@ -790,7 +782,7 @@ fn handle_rustc_crates(
790
782
crate_graph,
791
783
& rustc_workspace[ pkg] ,
792
784
build_scripts. get_output ( pkg) ,
793
- cfg_options,
785
+ cfg_options. clone ( ) ,
794
786
& mut |path| load_proc_macro ( & rustc_workspace[ tgt] . name , path) ,
795
787
file_id,
796
788
& rustc_workspace[ tgt] . name ,
@@ -845,15 +837,21 @@ fn add_target_crate_root(
845
837
crate_graph : & mut CrateGraph ,
846
838
pkg : & PackageData ,
847
839
build_data : Option < & BuildScriptOutput > ,
848
- cfg_options : & CfgOptions ,
840
+ cfg_options : CfgOptions ,
849
841
load_proc_macro : & mut dyn FnMut ( & AbsPath ) -> ProcMacroLoadResult ,
850
842
file_id : FileId ,
851
843
cargo_name : & str ,
852
844
is_proc_macro : bool ,
853
845
) -> CrateId {
854
846
let edition = pkg. edition ;
847
+ let mut potential_cfg_options = cfg_options. clone ( ) ;
848
+ potential_cfg_options. extend (
849
+ pkg. features
850
+ . iter ( )
851
+ . map ( |feat| CfgFlag :: KeyValue { key : "feature" . into ( ) , value : feat. 0 . into ( ) } ) ,
852
+ ) ;
855
853
let cfg_options = {
856
- let mut opts = cfg_options. clone ( ) ;
854
+ let mut opts = cfg_options;
857
855
for feature in pkg. active_features . iter ( ) {
858
856
opts. insert_key_value ( "feature" . into ( ) , feature. into ( ) ) ;
859
857
}
@@ -878,12 +876,6 @@ fn add_target_crate_root(
878
876
} ;
879
877
880
878
let display_name = CrateDisplayName :: from_canonical_name ( cargo_name. to_string ( ) ) ;
881
- let mut potential_cfg_options = cfg_options. clone ( ) ;
882
- potential_cfg_options. extend (
883
- pkg. features
884
- . iter ( )
885
- . map ( |feat| CfgFlag :: KeyValue { key : "feature" . into ( ) , value : feat. 0 . into ( ) } ) ,
886
- ) ;
887
879
crate_graph. add_crate_root (
888
880
file_id,
889
881
edition,
0 commit comments