@@ -8,6 +8,7 @@ use std::mem;
88use std:: ops;
99
1010use rustc_ast:: { LitKind , MetaItem , MetaItemKind , NestedMetaItem } ;
11+ use rustc_data_structures:: fx:: FxHashSet ;
1112use rustc_feature:: Features ;
1213use rustc_session:: parse:: ParseSess ;
1314use rustc_span:: symbol:: { sym, Symbol } ;
@@ -45,7 +46,7 @@ impl Cfg {
4546 /// Parses a `NestedMetaItem` into a `Cfg`.
4647 fn parse_nested (
4748 nested_cfg : & NestedMetaItem ,
48- exclude : & [ Symbol ] ,
49+ exclude : & FxHashSet < Cfg > ,
4950 ) -> Result < Option < Cfg > , InvalidCfgError > {
5051 match nested_cfg {
5152 NestedMetaItem :: MetaItem ( ref cfg) => Cfg :: parse_without ( cfg, exclude) ,
@@ -57,7 +58,7 @@ impl Cfg {
5758
5859 crate fn parse_without (
5960 cfg : & MetaItem ,
60- exclude : & [ Symbol ] ,
61+ exclude : & FxHashSet < Cfg > ,
6162 ) -> Result < Option < Cfg > , InvalidCfgError > {
6263 let name = match cfg. ident ( ) {
6364 Some ( ident) => ident. name ,
@@ -70,19 +71,13 @@ impl Cfg {
7071 } ;
7172 match cfg. kind {
7273 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) ) }
7876 }
7977 MetaItemKind :: NameValue ( ref lit) => match lit. kind {
8078 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) ) }
8681 }
8782 _ => Err ( InvalidCfgError {
8883 // FIXME: if the main #[cfg] syntax decided to support non-string literals,
@@ -126,7 +121,7 @@ impl Cfg {
126121 /// If the content is not properly formatted, it will return an error indicating what and where
127122 /// the error is.
128123 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 ( ) )
130125 }
131126
132127 /// Checks whether the given configuration can be matched in the current session.
0 commit comments