@@ -8,6 +8,7 @@ use std::mem;
8
8
use std:: ops;
9
9
10
10
use rustc_ast:: { LitKind , MetaItem , MetaItemKind , NestedMetaItem } ;
11
+ use rustc_data_structures:: fx:: FxHashSet ;
11
12
use rustc_feature:: Features ;
12
13
use rustc_session:: parse:: ParseSess ;
13
14
use rustc_span:: symbol:: { sym, Symbol } ;
@@ -45,7 +46,7 @@ impl Cfg {
45
46
/// Parses a `NestedMetaItem` into a `Cfg`.
46
47
fn parse_nested (
47
48
nested_cfg : & NestedMetaItem ,
48
- exclude : & [ Symbol ] ,
49
+ exclude : & FxHashSet < Cfg > ,
49
50
) -> Result < Option < Cfg > , InvalidCfgError > {
50
51
match nested_cfg {
51
52
NestedMetaItem :: MetaItem ( ref cfg) => Cfg :: parse_without ( cfg, exclude) ,
@@ -57,7 +58,7 @@ impl Cfg {
57
58
58
59
crate fn parse_without (
59
60
cfg : & MetaItem ,
60
- exclude : & [ Symbol ] ,
61
+ exclude : & FxHashSet < Cfg > ,
61
62
) -> Result < Option < Cfg > , InvalidCfgError > {
62
63
let name = match cfg. ident ( ) {
63
64
Some ( ident) => ident. name ,
@@ -70,19 +71,13 @@ impl Cfg {
70
71
} ;
71
72
match cfg. kind {
72
73
MetaItemKind :: Word => {
73
- if exclude. contains ( & name) {
74
- Ok ( None )
75
- } else {
76
- Ok ( Some ( Cfg :: Cfg ( name, None ) ) )
77
- }
74
+ let cfg = Cfg :: Cfg ( name, None ) ;
75
+ if exclude. contains ( & cfg) { Ok ( None ) } else { Ok ( Some ( cfg) ) }
78
76
}
79
77
MetaItemKind :: NameValue ( ref lit) => match lit. kind {
80
78
LitKind :: Str ( value, _) => {
81
- if exclude. contains ( & name) {
82
- Ok ( None )
83
- } else {
84
- Ok ( Some ( Cfg :: Cfg ( name, Some ( value) ) ) )
85
- }
79
+ let cfg = Cfg :: Cfg ( name, Some ( value) ) ;
80
+ if exclude. contains ( & cfg) { Ok ( None ) } else { Ok ( Some ( cfg) ) }
86
81
}
87
82
_ => Err ( InvalidCfgError {
88
83
// FIXME: if the main #[cfg] syntax decided to support non-string literals,
@@ -126,7 +121,7 @@ impl Cfg {
126
121
/// If the content is not properly formatted, it will return an error indicating what and where
127
122
/// the error is.
128
123
crate fn parse ( cfg : & MetaItem ) -> Result < Cfg , InvalidCfgError > {
129
- Self :: parse_without ( cfg, & [ ] ) . map ( |ret| ret. unwrap ( ) )
124
+ Self :: parse_without ( cfg, & FxHashSet :: default ( ) ) . map ( |ret| ret. unwrap ( ) )
130
125
}
131
126
132
127
/// Checks whether the given configuration can be matched in the current session.
0 commit comments