@@ -13,8 +13,7 @@ use rustc_feature::Features;
1313use rustc_session:: parse:: ParseSess ;
1414use rustc_span:: symbol:: { sym, Symbol } ;
1515
16- use rustc_span:: Span ;
17-
16+ use crate :: errors:: InvalidCfgError ;
1817use crate :: html:: escape:: Escape ;
1918
2019#[ cfg( test) ]
@@ -36,12 +35,6 @@ pub(crate) enum Cfg {
3635 All ( Vec < Cfg > ) ,
3736}
3837
39- #[ derive( PartialEq , Debug ) ]
40- pub ( crate ) struct InvalidCfgError {
41- pub ( crate ) msg : & ' static str ,
42- pub ( crate ) span : Span ,
43- }
44-
4538impl Cfg {
4639 /// Parses a `NestedMetaItem` into a `Cfg`.
4740 fn parse_nested (
@@ -51,7 +44,7 @@ impl Cfg {
5144 match nested_cfg {
5245 NestedMetaItem :: MetaItem ( ref cfg) => Cfg :: parse_without ( cfg, exclude) ,
5346 NestedMetaItem :: Lit ( ref lit) => {
54- Err ( InvalidCfgError { msg : "unexpected literal" , span : lit. span } )
47+ Err ( InvalidCfgError :: UnexpectedLiteral { span : lit. span } )
5548 }
5649 }
5750 }
@@ -63,10 +56,7 @@ impl Cfg {
6356 let name = match cfg. ident ( ) {
6457 Some ( ident) => ident. name ,
6558 None => {
66- return Err ( InvalidCfgError {
67- msg : "expected a single identifier" ,
68- span : cfg. span ,
69- } ) ;
59+ return Err ( InvalidCfgError :: ExpectedSingleIdentifier { span : cfg. span } ) ;
7060 }
7161 } ;
7262 match cfg. kind {
@@ -79,12 +69,9 @@ impl Cfg {
7969 let cfg = Cfg :: Cfg ( name, Some ( value) ) ;
8070 if exclude. contains ( & cfg) { Ok ( None ) } else { Ok ( Some ( cfg) ) }
8171 }
82- _ => Err ( InvalidCfgError {
83- // FIXME: if the main #[cfg] syntax decided to support non-string literals,
84- // this should be changed as well.
85- msg : "value of cfg option should be a string literal" ,
86- span : lit. span ,
87- } ) ,
72+ // FIXME: if the main #[cfg] syntax decided to support non-string literals, this
73+ // should be changed as well.
74+ _ => Err ( InvalidCfgError :: OptionValueNotStringLiteral { span : lit. span } ) ,
8875 } ,
8976 MetaItemKind :: List ( ref items) => {
9077 let orig_len = items. len ( ) ;
@@ -102,15 +89,12 @@ impl Cfg {
10289 return Ok ( None ) ;
10390 }
10491 } else {
105- Err ( InvalidCfgError { msg : "expected 1 cfg-pattern" , span : cfg. span } )
92+ Err ( InvalidCfgError :: ExpectedOneCfgPattern { span : cfg. span } )
10693 }
10794 }
108- _ => Err ( InvalidCfgError { msg : "invalid predicate" , span : cfg. span } ) ,
95+ _ => Err ( InvalidCfgError :: InvalidPredicate { span : cfg. span } ) ,
10996 } ;
110- match ret {
111- Ok ( c) => Ok ( Some ( c) ) ,
112- Err ( e) => Err ( e) ,
113- }
97+ ret. map ( |c| Some ( c) )
11498 }
11599 }
116100 }
0 commit comments