@@ -13,8 +13,7 @@ use rustc_feature::Features;
13
13
use rustc_session:: parse:: ParseSess ;
14
14
use rustc_span:: symbol:: { sym, Symbol } ;
15
15
16
- use rustc_span:: Span ;
17
-
16
+ use crate :: errors:: InvalidCfgError ;
18
17
use crate :: html:: escape:: Escape ;
19
18
20
19
#[ cfg( test) ]
@@ -36,12 +35,6 @@ pub(crate) enum Cfg {
36
35
All ( Vec < Cfg > ) ,
37
36
}
38
37
39
- #[ derive( PartialEq , Debug ) ]
40
- pub ( crate ) struct InvalidCfgError {
41
- pub ( crate ) msg : & ' static str ,
42
- pub ( crate ) span : Span ,
43
- }
44
-
45
38
impl Cfg {
46
39
/// Parses a `NestedMetaItem` into a `Cfg`.
47
40
fn parse_nested (
@@ -51,7 +44,7 @@ impl Cfg {
51
44
match nested_cfg {
52
45
NestedMetaItem :: MetaItem ( ref cfg) => Cfg :: parse_without ( cfg, exclude) ,
53
46
NestedMetaItem :: Lit ( ref lit) => {
54
- Err ( InvalidCfgError { msg : "unexpected literal" , span : lit. span } )
47
+ Err ( InvalidCfgError :: UnexpectedLiteral { span : lit. span } )
55
48
}
56
49
}
57
50
}
@@ -63,10 +56,7 @@ impl Cfg {
63
56
let name = match cfg. ident ( ) {
64
57
Some ( ident) => ident. name ,
65
58
None => {
66
- return Err ( InvalidCfgError {
67
- msg : "expected a single identifier" ,
68
- span : cfg. span ,
69
- } ) ;
59
+ return Err ( InvalidCfgError :: ExpectedSingleIdentifier { span : cfg. span } ) ;
70
60
}
71
61
} ;
72
62
match cfg. kind {
@@ -79,12 +69,9 @@ impl Cfg {
79
69
let cfg = Cfg :: Cfg ( name, Some ( value) ) ;
80
70
if exclude. contains ( & cfg) { Ok ( None ) } else { Ok ( Some ( cfg) ) }
81
71
}
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 } ) ,
88
75
} ,
89
76
MetaItemKind :: List ( ref items) => {
90
77
let orig_len = items. len ( ) ;
@@ -102,15 +89,12 @@ impl Cfg {
102
89
return Ok ( None ) ;
103
90
}
104
91
} else {
105
- Err ( InvalidCfgError { msg : "expected 1 cfg-pattern" , span : cfg. span } )
92
+ Err ( InvalidCfgError :: ExpectedOneCfgPattern { span : cfg. span } )
106
93
}
107
94
}
108
- _ => Err ( InvalidCfgError { msg : "invalid predicate" , span : cfg. span } ) ,
95
+ _ => Err ( InvalidCfgError :: InvalidPredicate { span : cfg. span } ) ,
109
96
} ;
110
- match ret {
111
- Ok ( c) => Ok ( Some ( c) ) ,
112
- Err ( e) => Err ( e) ,
113
- }
97
+ ret. map ( |c| Some ( c) )
114
98
}
115
99
}
116
100
}
0 commit comments