1
- //! Parsing and validation of builtin attributes
2
-
3
- use rustc_ast:: { self as ast, LitKind , MetaItem , MetaItemInner , MetaItemKind , MetaItemLit , NodeId } ;
1
+ // TODO: convert cfg properly.... And learn how cfg works I guess
2
+ use rustc_ast:: { LitKind , MetaItem , MetaItemInner , MetaItemKind , MetaItemLit , NodeId } ;
4
3
use rustc_ast_pretty:: pprust;
5
4
use rustc_attr_data_structures:: RustcVersion ;
6
5
use rustc_feature:: { Features , GatedCfg , find_gated_cfg} ;
@@ -9,10 +8,11 @@ use rustc_session::config::ExpectedValues;
9
8
use rustc_session:: lint:: BuiltinLintDiag ;
10
9
use rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ;
11
10
use rustc_session:: parse:: feature_err;
12
- use rustc_span:: { Span , Symbol , kw, sym} ;
11
+ use rustc_span:: symbol:: kw;
12
+ use rustc_span:: { Span , Symbol , sym} ;
13
13
14
- use crate :: util :: UnsupportedLiteralReason ;
15
- use crate :: { fluent_generated, parse_version, session_diagnostics } ;
14
+ use crate :: session_diagnostics :: { self , UnsupportedLiteralReason } ;
15
+ use crate :: { fluent_generated, parse_version} ;
16
16
17
17
#[ derive( Clone , Debug ) ]
18
18
pub struct Condition {
@@ -25,7 +25,7 @@ pub struct Condition {
25
25
26
26
/// Tests if a cfg-pattern matches the cfg set
27
27
pub fn cfg_matches (
28
- cfg : & ast :: MetaItemInner ,
28
+ cfg : & MetaItemInner ,
29
29
sess : & Session ,
30
30
lint_node_id : NodeId ,
31
31
features : Option < & Features > ,
@@ -80,16 +80,16 @@ fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &Session, features: &Fea
80
80
/// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to
81
81
/// evaluate individual items.
82
82
pub fn eval_condition (
83
- cfg : & ast :: MetaItemInner ,
83
+ cfg : & MetaItemInner ,
84
84
sess : & Session ,
85
85
features : Option < & Features > ,
86
86
eval : & mut impl FnMut ( Condition ) -> bool ,
87
87
) -> bool {
88
88
let dcx = sess. dcx ( ) ;
89
89
90
90
let cfg = match cfg {
91
- ast :: MetaItemInner :: MetaItem ( meta_item) => meta_item,
92
- ast :: MetaItemInner :: Lit ( MetaItemLit { kind : LitKind :: Bool ( b) , .. } ) => {
91
+ MetaItemInner :: MetaItem ( meta_item) => meta_item,
92
+ MetaItemInner :: Lit ( MetaItemLit { kind : LitKind :: Bool ( b) , .. } ) => {
93
93
if let Some ( features) = features {
94
94
// we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
95
95
// and `true`, and we want to keep the former working without feature gate
@@ -118,7 +118,7 @@ pub fn eval_condition(
118
118
} ;
119
119
120
120
match & cfg. kind {
121
- ast :: MetaItemKind :: List ( mis) if cfg. name_or_empty ( ) == sym:: version => {
121
+ MetaItemKind :: List ( mis) if cfg. name_or_empty ( ) == sym:: version => {
122
122
try_gate_cfg ( sym:: version, cfg. span , sess, features) ;
123
123
let ( min_version, span) = match & mis[ ..] {
124
124
[ MetaItemInner :: Lit ( MetaItemLit { kind : LitKind :: Str ( sym, ..) , span, .. } ) ] => {
@@ -150,7 +150,7 @@ pub fn eval_condition(
150
150
RustcVersion :: CURRENT >= min_version
151
151
}
152
152
}
153
- ast :: MetaItemKind :: List ( mis) => {
153
+ MetaItemKind :: List ( mis) => {
154
154
for mi in mis. iter ( ) {
155
155
if mi. meta_item_or_bool ( ) . is_none ( ) {
156
156
dcx. emit_err ( session_diagnostics:: UnsupportedLiteral {
@@ -209,12 +209,7 @@ pub fn eval_condition(
209
209
seg. ident . name = Symbol :: intern ( & format ! ( "target_{}" , seg. ident. name) ) ;
210
210
}
211
211
212
- res & eval_condition (
213
- & ast:: MetaItemInner :: MetaItem ( mi) ,
214
- sess,
215
- features,
216
- eval,
217
- )
212
+ res & eval_condition ( & MetaItemInner :: MetaItem ( mi) , sess, features, eval)
218
213
} )
219
214
}
220
215
_ => {
@@ -226,7 +221,7 @@ pub fn eval_condition(
226
221
}
227
222
}
228
223
}
229
- ast :: MetaItemKind :: Word | MetaItemKind :: NameValue ( ..) if cfg. path . segments . len ( ) != 1 => {
224
+ MetaItemKind :: Word | MetaItemKind :: NameValue ( ..) if cfg. path . segments . len ( ) != 1 => {
230
225
dcx. emit_err ( session_diagnostics:: CfgPredicateIdentifier { span : cfg. path . span } ) ;
231
226
true
232
227
}
@@ -239,7 +234,7 @@ pub fn eval_condition(
239
234
} ) ;
240
235
true
241
236
}
242
- ast :: MetaItemKind :: Word | ast :: MetaItemKind :: NameValue ( ..) => {
237
+ MetaItemKind :: Word | MetaItemKind :: NameValue ( ..) => {
243
238
let ident = cfg. ident ( ) . expect ( "multi-segment cfg predicate" ) ;
244
239
eval ( Condition {
245
240
name : ident. name ,
0 commit comments