@@ -42,6 +42,15 @@ impl CfgOverrides {
42
42
pub fn len ( & self ) -> usize {
43
43
self . global . len ( ) + self . selective . values ( ) . map ( |it| it. len ( ) ) . sum :: < usize > ( )
44
44
}
45
+
46
+ fn apply ( & self , cfg_options : & mut CfgOptions , name : & str ) {
47
+ if !self . global . is_empty ( ) {
48
+ cfg_options. apply_diff ( self . global . clone ( ) ) ;
49
+ } ;
50
+ if let Some ( diff) = self . selective . get ( name) {
51
+ cfg_options. apply_diff ( diff. clone ( ) ) ;
52
+ } ;
53
+ }
45
54
}
46
55
47
56
/// `PackageRoot` describes a package root folder.
@@ -983,25 +992,13 @@ fn cargo_to_crate_graph(
983
992
let cfg_options = {
984
993
let mut cfg_options = cfg_options. clone ( ) ;
985
994
986
- // Add test cfg for local crates
987
995
if cargo[ pkg] . is_local {
996
+ // Add test cfg for local crates
988
997
cfg_options. insert_atom ( "test" . into ( ) ) ;
989
998
cfg_options. insert_atom ( "rust_analyzer" . into ( ) ) ;
990
999
}
991
1000
992
- if !override_cfg. global . is_empty ( ) {
993
- cfg_options. apply_diff ( override_cfg. global . clone ( ) ) ;
994
- } ;
995
- if let Some ( diff) = override_cfg. selective . get ( & cargo[ pkg] . name ) {
996
- // FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
997
- // in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
998
- // working on rust-lang/rust as that's the only time it appears outside sysroot).
999
- //
1000
- // A more ideal solution might be to reanalyze crates based on where the cursor is and
1001
- // figure out the set of cfgs that would have to apply to make it active.
1002
-
1003
- cfg_options. apply_diff ( diff. clone ( ) ) ;
1004
- } ;
1001
+ override_cfg. apply ( & mut cfg_options, & cargo[ pkg] . name ) ;
1005
1002
cfg_options
1006
1003
} ;
1007
1004
@@ -1115,13 +1112,7 @@ fn cargo_to_crate_graph(
1115
1112
& pkg_crates,
1116
1113
& cfg_options,
1117
1114
override_cfg,
1118
- if rustc_workspace. workspace_root ( ) == cargo. workspace_root ( ) {
1119
- // the rustc workspace does not use the installed toolchain's proc-macro server
1120
- // so we need to make sure we don't use the pre compiled proc-macros there either
1121
- build_scripts
1122
- } else {
1123
- rustc_build_scripts
1124
- } ,
1115
+ rustc_build_scripts,
1125
1116
) ;
1126
1117
}
1127
1118
}
@@ -1212,20 +1203,7 @@ fn handle_rustc_crates(
1212
1203
}
1213
1204
1214
1205
let mut cfg_options = cfg_options. clone ( ) ;
1215
-
1216
- if !override_cfg. global . is_empty ( ) {
1217
- cfg_options. apply_diff ( override_cfg. global . clone ( ) ) ;
1218
- } ;
1219
- if let Some ( diff) = override_cfg. selective . get ( & rustc_workspace[ pkg] . name ) {
1220
- // FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
1221
- // in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
1222
- // working on rust-lang/rust as that's the only time it appears outside sysroot).
1223
- //
1224
- // A more ideal solution might be to reanalyze crates based on where the cursor is and
1225
- // figure out the set of cfgs that would have to apply to make it active.
1226
-
1227
- cfg_options. apply_diff ( diff. clone ( ) ) ;
1228
- } ;
1206
+ override_cfg. apply ( & mut cfg_options, & rustc_workspace[ pkg] . name ) ;
1229
1207
1230
1208
for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
1231
1209
let kind @ TargetKind :: Lib { is_proc_macro } = rustc_workspace[ tgt] . kind else {
0 commit comments