@@ -43,6 +43,15 @@ impl CfgOverrides {
4343 pub fn len ( & self ) -> usize {
4444 self . global . len ( ) + self . selective . values ( ) . map ( |it| it. len ( ) ) . sum :: < usize > ( )
4545 }
46+
47+ fn apply ( & self , cfg_options : & mut CfgOptions , name : & str ) {
48+ if !self . global . is_empty ( ) {
49+ cfg_options. apply_diff ( self . global . clone ( ) ) ;
50+ } ;
51+ if let Some ( diff) = self . selective . get ( name) {
52+ cfg_options. apply_diff ( diff. clone ( ) ) ;
53+ } ;
54+ }
4655}
4756
4857/// `PackageRoot` describes a package root folder.
@@ -999,25 +1008,13 @@ fn cargo_to_crate_graph(
9991008 let cfg_options = {
10001009 let mut cfg_options = cfg_options. clone ( ) ;
10011010
1002- // Add test cfg for local crates
10031011 if cargo[ pkg] . is_local {
1012+ // Add test cfg for local crates
10041013 cfg_options. insert_atom ( "test" . into ( ) ) ;
10051014 cfg_options. insert_atom ( "rust_analyzer" . into ( ) ) ;
10061015 }
10071016
1008- if !override_cfg. global . is_empty ( ) {
1009- cfg_options. apply_diff ( override_cfg. global . clone ( ) ) ;
1010- } ;
1011- if let Some ( diff) = override_cfg. selective . get ( & cargo[ pkg] . name ) {
1012- // FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
1013- // in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
1014- // working on rust-lang/rust as that's the only time it appears outside sysroot).
1015- //
1016- // A more ideal solution might be to reanalyze crates based on where the cursor is and
1017- // figure out the set of cfgs that would have to apply to make it active.
1018-
1019- cfg_options. apply_diff ( diff. clone ( ) ) ;
1020- } ;
1017+ override_cfg. apply ( & mut cfg_options, & cargo[ pkg] . name ) ;
10211018 cfg_options
10221019 } ;
10231020
@@ -1153,6 +1150,7 @@ fn cargo_to_crate_graph(
11531150 & pkg_crates,
11541151 & cfg_options,
11551152 override_cfg,
1153+ // FIXME: Remove this once rustc switched over to rust-project.json
11561154 if rustc_workspace. workspace_root ( ) == cargo. workspace_root ( ) {
11571155 // the rustc workspace does not use the installed toolchain's proc-macro server
11581156 // so we need to make sure we don't use the pre compiled proc-macros there either
@@ -1250,20 +1248,7 @@ fn handle_rustc_crates(
12501248 }
12511249
12521250 let mut cfg_options = cfg_options. clone ( ) ;
1253-
1254- if !override_cfg. global . is_empty ( ) {
1255- cfg_options. apply_diff ( override_cfg. global . clone ( ) ) ;
1256- } ;
1257- if let Some ( diff) = override_cfg. selective . get ( & rustc_workspace[ pkg] . name ) {
1258- // FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
1259- // in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
1260- // working on rust-lang/rust as that's the only time it appears outside sysroot).
1261- //
1262- // A more ideal solution might be to reanalyze crates based on where the cursor is and
1263- // figure out the set of cfgs that would have to apply to make it active.
1264-
1265- cfg_options. apply_diff ( diff. clone ( ) ) ;
1266- } ;
1251+ override_cfg. apply ( & mut cfg_options, & rustc_workspace[ pkg] . name ) ;
12671252
12681253 for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
12691254 let kind @ TargetKind :: Lib { is_proc_macro } = rustc_workspace[ tgt] . kind else {
0 commit comments