@@ -548,8 +548,7 @@ fn cargo_to_crate_graph(
548548 let mut has_private = false ;
549549 // Next, create crates for each package, target pair
550550 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 ( ) ;
553552
554553 let overrides = match override_cfg {
555554 CfgOverrides :: Wildcard ( cfg_diff) => Some ( cfg_diff) ,
@@ -558,9 +557,7 @@ fn cargo_to_crate_graph(
558557
559558 // Add test cfg for local crates
560559 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 ( ) ) ;
564561 }
565562
566563 if let Some ( overrides) = overrides {
@@ -571,9 +568,7 @@ fn cargo_to_crate_graph(
571568 // A more ideal solution might be to reanalyze crates based on where the cursor is and
572569 // figure out the set of cfgs that would have to apply to make it active.
573570
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 ( ) ) ;
577572 } ;
578573
579574 has_private |= cargo[ pkg] . metadata . rustc_private ;
@@ -593,7 +588,7 @@ fn cargo_to_crate_graph(
593588 & mut crate_graph,
594589 & cargo[ pkg] ,
595590 build_scripts. get_output ( pkg) ,
596- cfg_options,
591+ cfg_options. clone ( ) ,
597592 & mut |path| load_proc_macro ( & cargo[ tgt] . name , path) ,
598593 file_id,
599594 & cargo[ tgt] . name ,
@@ -758,8 +753,7 @@ fn handle_rustc_crates(
758753 queue. push_back ( dep. pkg ) ;
759754 }
760755
761- let mut cfg_options = cfg_options;
762- let mut replaced_cfg_options;
756+ let mut cfg_options = cfg_options. clone ( ) ;
763757
764758 let overrides = match override_cfg {
765759 CfgOverrides :: Wildcard ( cfg_diff) => Some ( cfg_diff) ,
@@ -776,9 +770,7 @@ fn handle_rustc_crates(
776770 // A more ideal solution might be to reanalyze crates based on where the cursor is and
777771 // figure out the set of cfgs that would have to apply to make it active.
778772
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 ( ) ) ;
782774 } ;
783775
784776 for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
@@ -790,7 +782,7 @@ fn handle_rustc_crates(
790782 crate_graph,
791783 & rustc_workspace[ pkg] ,
792784 build_scripts. get_output ( pkg) ,
793- cfg_options,
785+ cfg_options. clone ( ) ,
794786 & mut |path| load_proc_macro ( & rustc_workspace[ tgt] . name , path) ,
795787 file_id,
796788 & rustc_workspace[ tgt] . name ,
@@ -845,15 +837,21 @@ fn add_target_crate_root(
845837 crate_graph : & mut CrateGraph ,
846838 pkg : & PackageData ,
847839 build_data : Option < & BuildScriptOutput > ,
848- cfg_options : & CfgOptions ,
840+ cfg_options : CfgOptions ,
849841 load_proc_macro : & mut dyn FnMut ( & AbsPath ) -> ProcMacroLoadResult ,
850842 file_id : FileId ,
851843 cargo_name : & str ,
852844 is_proc_macro : bool ,
853845) -> CrateId {
854846 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+ ) ;
855853 let cfg_options = {
856- let mut opts = cfg_options. clone ( ) ;
854+ let mut opts = cfg_options;
857855 for feature in pkg. active_features . iter ( ) {
858856 opts. insert_key_value ( "feature" . into ( ) , feature. into ( ) ) ;
859857 }
@@ -878,12 +876,6 @@ fn add_target_crate_root(
878876 } ;
879877
880878 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- ) ;
887879 crate_graph. add_crate_root (
888880 file_id,
889881 edition,
0 commit comments