@@ -28,29 +28,17 @@ use crate::{
2828} ;
2929
3030/// 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 ,
3835 /// 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 > ,
4637}
4738
4839impl CfgOverrides {
4940 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 > ( )
5442 }
5543}
5644
@@ -292,7 +280,7 @@ impl ProjectWorkspace {
292280 let rustc_cfg =
293281 rustc_cfg:: get ( Some ( & cargo_toml) , config. target . as_deref ( ) , & config. extra_env ) ;
294282
295- let cfg_overrides = config. cfg_overrides ( ) ;
283+ let cfg_overrides = config. cfg_overrides . clone ( ) ;
296284 let data_layout = target_data_layout:: get (
297285 Some ( & cargo_toml) ,
298286 config. target . as_deref ( ) ,
@@ -886,20 +874,18 @@ fn cargo_to_crate_graph(
886874 cfg_options. insert_atom ( "test" . into ( ) ) ;
887875 }
888876
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 ( ) ) ;
892879 } ;
893-
894- if let Some ( overrides) = overrides {
880+ if let Some ( diff) = override_cfg. selective . get ( & cargo[ pkg] . name ) {
895881 // FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
896882 // in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
897883 // working on rust-lang/rust as that's the only time it appears outside sysroot).
898884 //
899885 // A more ideal solution might be to reanalyze crates based on where the cursor is and
900886 // figure out the set of cfgs that would have to apply to make it active.
901887
902- cfg_options. apply_diff ( overrides . clone ( ) ) ;
888+ cfg_options. apply_diff ( diff . clone ( ) ) ;
903889 } ;
904890 cfg_options
905891 } ) ;
@@ -1109,22 +1095,18 @@ fn handle_rustc_crates(
11091095
11101096 let mut cfg_options = cfg_options. clone ( ) ;
11111097
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 ( ) ) ;
11171100 } ;
1118-
1119- if let Some ( overrides) = overrides {
1101+ if let Some ( diff) = override_cfg. selective . get ( & rustc_workspace[ pkg] . name ) {
11201102 // FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
11211103 // in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
11221104 // working on rust-lang/rust as that's the only time it appears outside sysroot).
11231105 //
11241106 // A more ideal solution might be to reanalyze crates based on where the cursor is and
11251107 // figure out the set of cfgs that would have to apply to make it active.
11261108
1127- cfg_options. apply_diff ( overrides . clone ( ) ) ;
1109+ cfg_options. apply_diff ( diff . clone ( ) ) ;
11281110 } ;
11291111
11301112 for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
0 commit comments