@@ -43,6 +43,15 @@ impl CfgOverrides {
43
43
pub fn len ( & self ) -> usize {
44
44
self . global . len ( ) + self . selective . values ( ) . map ( |it| it. len ( ) ) . sum :: < usize > ( )
45
45
}
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
+ }
46
55
}
47
56
48
57
/// `PackageRoot` describes a package root folder.
@@ -999,25 +1008,13 @@ fn cargo_to_crate_graph(
999
1008
let cfg_options = {
1000
1009
let mut cfg_options = cfg_options. clone ( ) ;
1001
1010
1002
- // Add test cfg for local crates
1003
1011
if cargo[ pkg] . is_local {
1012
+ // Add test cfg for local crates
1004
1013
cfg_options. insert_atom ( "test" . into ( ) ) ;
1005
1014
cfg_options. insert_atom ( "rust_analyzer" . into ( ) ) ;
1006
1015
}
1007
1016
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 ) ;
1021
1018
cfg_options
1022
1019
} ;
1023
1020
@@ -1153,6 +1150,7 @@ fn cargo_to_crate_graph(
1153
1150
& pkg_crates,
1154
1151
& cfg_options,
1155
1152
override_cfg,
1153
+ // FIXME: Remove this once rustc switched over to rust-project.json
1156
1154
if rustc_workspace. workspace_root ( ) == cargo. workspace_root ( ) {
1157
1155
// the rustc workspace does not use the installed toolchain's proc-macro server
1158
1156
// 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(
1250
1248
}
1251
1249
1252
1250
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 ) ;
1267
1252
1268
1253
for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
1269
1254
let kind @ TargetKind :: Lib { is_proc_macro } = rustc_workspace[ tgt] . kind else {
0 commit comments