@@ -18,7 +18,7 @@ use ast;
1818use ast:: { AttrId , Attribute , Name } ;
1919use ast:: { MetaItem , MetaItemKind , NestedMetaItem , NestedMetaItemKind } ;
2020use ast:: { Lit , Expr , Item , Local , Stmt , StmtKind } ;
21- use codemap:: { respan , spanned, dummy_spanned, mk_sp} ;
21+ use codemap:: { spanned, dummy_spanned, mk_sp} ;
2222use syntax_pos:: { Span , BytePos , DUMMY_SP } ;
2323use errors:: Handler ;
2424use feature_gate:: { Features , GatedCfg } ;
@@ -219,16 +219,12 @@ impl Attribute {
219219
220220impl MetaItem {
221221 pub fn name ( & self ) -> Name {
222- match self . node {
223- MetaItemKind :: Word ( n) => n,
224- MetaItemKind :: NameValue ( n, _) => n,
225- MetaItemKind :: List ( n, _) => n,
226- }
222+ self . name
227223 }
228224
229225 pub fn value_str ( & self ) -> Option < InternedString > {
230226 match self . node {
231- MetaItemKind :: NameValue ( _ , ref v) => {
227+ MetaItemKind :: NameValue ( ref v) => {
232228 match v. node {
233229 ast:: LitKind :: Str ( ref s, _) => Some ( ( * s) . clone ( ) ) ,
234230 _ => None ,
@@ -240,14 +236,14 @@ impl MetaItem {
240236
241237 pub fn meta_item_list ( & self ) -> Option < & [ NestedMetaItem ] > {
242238 match self . node {
243- MetaItemKind :: List ( _ , ref l) => Some ( & l[ ..] ) ,
239+ MetaItemKind :: List ( ref l) => Some ( & l[ ..] ) ,
244240 _ => None
245241 }
246242 }
247243
248244 pub fn is_word ( & self ) -> bool {
249245 match self . node {
250- MetaItemKind :: Word ( _ ) => true ,
246+ MetaItemKind :: Word => true ,
251247 _ => false ,
252248 }
253249 }
@@ -320,15 +316,15 @@ pub fn mk_word_item(name: Name) -> P<MetaItem> {
320316}
321317
322318pub fn mk_spanned_name_value_item ( sp : Span , name : Name , value : ast:: Lit ) -> P < MetaItem > {
323- P ( respan ( sp, MetaItemKind :: NameValue ( name , value) ) )
319+ P ( MetaItem { span : sp, name : name , node : MetaItemKind :: NameValue ( value) } )
324320}
325321
326322pub fn mk_spanned_list_item ( sp : Span , name : Name , items : Vec < NestedMetaItem > ) -> P < MetaItem > {
327- P ( respan ( sp, MetaItemKind :: List ( name , items) ) )
323+ P ( MetaItem { span : sp, name : name , node : MetaItemKind :: List ( items) } )
328324}
329325
330326pub fn mk_spanned_word_item ( sp : Span , name : Name ) -> P < MetaItem > {
331- P ( respan ( sp, MetaItemKind :: Word ( name ) ) )
327+ P ( MetaItem { span : sp, name : name , node : MetaItemKind :: Word } )
332328}
333329
334330
@@ -394,7 +390,11 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: By
394390 Attribute {
395391 id : id,
396392 style : style,
397- value : P ( spanned ( lo, hi, MetaItemKind :: NameValue ( token:: intern ( "doc" ) , lit) ) ) ,
393+ value : P ( MetaItem {
394+ span : mk_sp ( lo, hi) ,
395+ name : token:: intern ( "doc" ) ,
396+ node : MetaItemKind :: NameValue ( lit) ,
397+ } ) ,
398398 is_sugared_doc : true ,
399399 span : mk_sp ( lo, hi) ,
400400 }
@@ -472,13 +472,14 @@ pub enum InlineAttr {
472472
473473/// Determine what `#[inline]` attribute is present in `attrs`, if any.
474474pub fn find_inline_attr ( diagnostic : Option < & Handler > , attrs : & [ Attribute ] ) -> InlineAttr {
475- attrs. iter ( ) . fold ( InlineAttr :: None , |ia, attr| {
475+ attrs. iter ( ) . fold ( InlineAttr :: None , |ia, attr| {
476476 match attr. value . node {
477- MetaItemKind :: Word ( n) if n == "inline" => {
477+ _ if attr. value . name != "inline" => ia,
478+ MetaItemKind :: Word => {
478479 mark_used ( attr) ;
479480 InlineAttr :: Hint
480481 }
481- MetaItemKind :: List ( n , ref items) if n == "inline" => {
482+ MetaItemKind :: List ( ref items) => {
482483 mark_used ( attr) ;
483484 if items. len ( ) != 1 {
484485 diagnostic. map ( |d|{ span_err ! ( d, attr. span, E0534 , "expected one argument" ) ; } ) ;
@@ -511,7 +512,7 @@ pub fn requests_inline(attrs: &[Attribute]) -> bool {
511512/// Tests if a cfg-pattern matches the cfg set
512513pub fn cfg_matches ( cfg : & ast:: MetaItem , sess : & ParseSess , features : Option < & Features > ) -> bool {
513514 match cfg. node {
514- ast:: MetaItemKind :: List ( ref pred , ref mis) => {
515+ ast:: MetaItemKind :: List ( ref mis) => {
515516 for mi in mis. iter ( ) {
516517 if !mi. is_meta_item ( ) {
517518 handle_errors ( & sess. span_diagnostic , mi. span , AttrError :: UnsupportedLiteral ) ;
@@ -521,7 +522,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
521522
522523 // The unwraps below may look dangerous, but we've already asserted
523524 // that they won't fail with the loop above.
524- match & * pred . as_str ( ) {
525+ match & * cfg . name . as_str ( ) {
525526 "any" => mis. iter ( ) . any ( |mi| {
526527 cfg_matches ( mi. meta_item ( ) . unwrap ( ) , sess, features)
527528 } ) ,
@@ -542,7 +543,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
542543 }
543544 }
544545 } ,
545- ast:: MetaItemKind :: Word ( _ ) | ast:: MetaItemKind :: NameValue ( ..) => {
546+ ast:: MetaItemKind :: Word | ast:: MetaItemKind :: NameValue ( ..) => {
546547 if let ( Some ( feats) , Some ( gated_cfg) ) = ( features, GatedCfg :: gate ( cfg) ) {
547548 gated_cfg. check_and_emit ( sess, feats) ;
548549 }
@@ -880,7 +881,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
880881pub fn find_repr_attrs ( diagnostic : & Handler , attr : & Attribute ) -> Vec < ReprAttr > {
881882 let mut acc = Vec :: new ( ) ;
882883 match attr. value . node {
883- ast:: MetaItemKind :: List ( s , ref items) if s == "repr" => {
884+ ast:: MetaItemKind :: List ( ref items) if attr . value . name == "repr" => {
884885 mark_used ( attr) ;
885886 for item in items {
886887 if !item. is_meta_item ( ) {
0 commit comments