@@ -28,29 +28,17 @@ use crate::{
28
28
} ;
29
29
30
30
/// A set of cfg-overrides per crate.
31
- ///
32
- /// `Wildcard(..)` is useful e.g. disabling `#[cfg(test)]` on all crates,
33
- /// without having to first obtain a list of all crates.
34
- #[ derive( Debug , Clone , Eq , PartialEq ) ]
35
- pub enum CfgOverrides {
36
- /// A single global set of overrides matching all crates.
37
- Wildcard ( CfgDiff ) ,
31
+ #[ derive( Default , Debug , Clone , Eq , PartialEq ) ]
32
+ pub struct CfgOverrides {
33
+ /// A global set of overrides matching all crates.
34
+ pub global : CfgDiff ,
38
35
/// A set of overrides matching specific crates.
39
- Selective ( FxHashMap < String , CfgDiff > ) ,
40
- }
41
-
42
- impl Default for CfgOverrides {
43
- fn default ( ) -> Self {
44
- Self :: Selective ( FxHashMap :: default ( ) )
45
- }
36
+ pub selective : FxHashMap < String , CfgDiff > ,
46
37
}
47
38
48
39
impl CfgOverrides {
49
40
pub fn len ( & self ) -> usize {
50
- match self {
51
- CfgOverrides :: Wildcard ( _) => 1 ,
52
- CfgOverrides :: Selective ( hash_map) => hash_map. len ( ) ,
53
- }
41
+ self . global . len ( ) + self . selective . iter ( ) . map ( |( _, it) | it. len ( ) ) . sum :: < usize > ( )
54
42
}
55
43
}
56
44
@@ -292,7 +280,7 @@ impl ProjectWorkspace {
292
280
let rustc_cfg =
293
281
rustc_cfg:: get ( Some ( & cargo_toml) , config. target . as_deref ( ) , & config. extra_env ) ;
294
282
295
- let cfg_overrides = config. cfg_overrides ( ) ;
283
+ let cfg_overrides = config. cfg_overrides . clone ( ) ;
296
284
let data_layout = target_data_layout:: get (
297
285
Some ( & cargo_toml) ,
298
286
config. target . as_deref ( ) ,
@@ -886,20 +874,18 @@ fn cargo_to_crate_graph(
886
874
cfg_options. insert_atom ( "test" . into ( ) ) ;
887
875
}
888
876
889
- let overrides = match override_cfg {
890
- CfgOverrides :: Wildcard ( cfg_diff) => Some ( cfg_diff) ,
891
- CfgOverrides :: Selective ( cfg_overrides) => cfg_overrides. get ( & cargo[ pkg] . name ) ,
877
+ if !override_cfg. global . is_empty ( ) {
878
+ cfg_options. apply_diff ( override_cfg. global . clone ( ) ) ;
892
879
} ;
893
-
894
- if let Some ( overrides) = overrides {
880
+ if let Some ( diff) = override_cfg. selective . get ( & cargo[ pkg] . name ) {
895
881
// FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
896
882
// in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
897
883
// working on rust-lang/rust as that's the only time it appears outside sysroot).
898
884
//
899
885
// A more ideal solution might be to reanalyze crates based on where the cursor is and
900
886
// figure out the set of cfgs that would have to apply to make it active.
901
887
902
- cfg_options. apply_diff ( overrides . clone ( ) ) ;
888
+ cfg_options. apply_diff ( diff . clone ( ) ) ;
903
889
} ;
904
890
cfg_options
905
891
} ) ;
@@ -1109,22 +1095,18 @@ fn handle_rustc_crates(
1109
1095
1110
1096
let mut cfg_options = cfg_options. clone ( ) ;
1111
1097
1112
- let overrides = match override_cfg {
1113
- CfgOverrides :: Wildcard ( cfg_diff) => Some ( cfg_diff) ,
1114
- CfgOverrides :: Selective ( cfg_overrides) => {
1115
- cfg_overrides. get ( & rustc_workspace[ pkg] . name )
1116
- }
1098
+ if !override_cfg. global . is_empty ( ) {
1099
+ cfg_options. apply_diff ( override_cfg. global . clone ( ) ) ;
1117
1100
} ;
1118
-
1119
- if let Some ( overrides) = overrides {
1101
+ if let Some ( diff) = override_cfg. selective . get ( & rustc_workspace[ pkg] . name ) {
1120
1102
// FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
1121
1103
// in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
1122
1104
// working on rust-lang/rust as that's the only time it appears outside sysroot).
1123
1105
//
1124
1106
// A more ideal solution might be to reanalyze crates based on where the cursor is and
1125
1107
// figure out the set of cfgs that would have to apply to make it active.
1126
1108
1127
- cfg_options. apply_diff ( overrides . clone ( ) ) ;
1109
+ cfg_options. apply_diff ( diff . clone ( ) ) ;
1128
1110
} ;
1129
1111
1130
1112
for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
0 commit comments