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 } ;
43use rustc_ast_pretty:: pprust;
54use rustc_attr_data_structures:: RustcVersion ;
65use rustc_feature:: { Features , GatedCfg , find_gated_cfg} ;
@@ -9,10 +8,11 @@ use rustc_session::config::ExpectedValues;
98use rustc_session:: lint:: BuiltinLintDiag ;
109use rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ;
1110use 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} ;
1313
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} ;
1616
1717#[ derive( Clone , Debug ) ]
1818pub struct Condition {
@@ -25,7 +25,7 @@ pub struct Condition {
2525
2626/// Tests if a cfg-pattern matches the cfg set
2727pub fn cfg_matches (
28- cfg : & ast :: MetaItemInner ,
28+ cfg : & MetaItemInner ,
2929 sess : & Session ,
3030 lint_node_id : NodeId ,
3131 features : Option < & Features > ,
@@ -80,16 +80,16 @@ fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &Session, features: &Fea
8080/// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to
8181/// evaluate individual items.
8282pub fn eval_condition (
83- cfg : & ast :: MetaItemInner ,
83+ cfg : & MetaItemInner ,
8484 sess : & Session ,
8585 features : Option < & Features > ,
8686 eval : & mut impl FnMut ( Condition ) -> bool ,
8787) -> bool {
8888 let dcx = sess. dcx ( ) ;
8989
9090 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) , .. } ) => {
9393 if let Some ( features) = features {
9494 // we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
9595 // and `true`, and we want to keep the former working without feature gate
@@ -118,7 +118,7 @@ pub fn eval_condition(
118118 } ;
119119
120120 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 => {
122122 try_gate_cfg ( sym:: version, cfg. span , sess, features) ;
123123 let ( min_version, span) = match & mis[ ..] {
124124 [ MetaItemInner :: Lit ( MetaItemLit { kind : LitKind :: Str ( sym, ..) , span, .. } ) ] => {
@@ -150,7 +150,7 @@ pub fn eval_condition(
150150 RustcVersion :: CURRENT >= min_version
151151 }
152152 }
153- ast :: MetaItemKind :: List ( mis) => {
153+ MetaItemKind :: List ( mis) => {
154154 for mi in mis. iter ( ) {
155155 if mi. meta_item_or_bool ( ) . is_none ( ) {
156156 dcx. emit_err ( session_diagnostics:: UnsupportedLiteral {
@@ -209,12 +209,7 @@ pub fn eval_condition(
209209 seg. ident . name = Symbol :: intern ( & format ! ( "target_{}" , seg. ident. name) ) ;
210210 }
211211
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)
218213 } )
219214 }
220215 _ => {
@@ -226,7 +221,7 @@ pub fn eval_condition(
226221 }
227222 }
228223 }
229- ast :: MetaItemKind :: Word | MetaItemKind :: NameValue ( ..) if cfg. path . segments . len ( ) != 1 => {
224+ MetaItemKind :: Word | MetaItemKind :: NameValue ( ..) if cfg. path . segments . len ( ) != 1 => {
230225 dcx. emit_err ( session_diagnostics:: CfgPredicateIdentifier { span : cfg. path . span } ) ;
231226 true
232227 }
@@ -239,7 +234,7 @@ pub fn eval_condition(
239234 } ) ;
240235 true
241236 }
242- ast :: MetaItemKind :: Word | ast :: MetaItemKind :: NameValue ( ..) => {
237+ MetaItemKind :: Word | MetaItemKind :: NameValue ( ..) => {
243238 let ident = cfg. ident ( ) . expect ( "multi-segment cfg predicate" ) ;
244239 eval ( Condition {
245240 name : ident. name ,
0 commit comments