@@ -26,10 +26,11 @@ pub use self::Visibility::*;
2626use syntax:: abi:: Abi ;
2727use syntax:: ast;
2828use syntax:: attr;
29- use syntax:: attr:: { AttributeMethods , AttrMetaMethods } ;
29+ use syntax:: attr:: { AttributeMethods , AttrMetaMethods , AttrNestedMetaItemMethods } ;
3030use syntax:: codemap:: Spanned ;
3131use syntax:: parse:: token:: { self , InternedString , keywords} ;
3232use syntax:: ptr:: P ;
33+ use syntax:: print:: pprust as syntax_pprust;
3334use syntax_pos:: { self , DUMMY_SP , Pos } ;
3435
3536use rustc_trans:: back:: link;
@@ -501,11 +502,24 @@ impl Attributes for [Attribute] {
501502 }
502503}
503504
505+ /// This is a flattened version of the AST's Attribute + MetaItem.
504506#[ derive( Clone , RustcEncodable , RustcDecodable , PartialEq , Debug ) ]
505507pub enum Attribute {
506508 Word ( String ) ,
507509 List ( String , Vec < Attribute > ) ,
508- NameValue ( String , String )
510+ NameValue ( String , String ) ,
511+ Literal ( String ) ,
512+ }
513+
514+ impl Clean < Attribute > for ast:: NestedMetaItem {
515+ fn clean ( & self , cx : & DocContext ) -> Attribute {
516+ if let Some ( mi) = self . meta_item ( ) {
517+ mi. clean ( cx)
518+ } else { // must be a literal
519+ let lit = self . literal ( ) . unwrap ( ) ;
520+ Literal ( syntax_pprust:: lit_to_string ( lit) )
521+ }
522+ }
509523}
510524
511525impl Clean < Attribute > for ast:: MetaItem {
@@ -528,12 +542,28 @@ impl Clean<Attribute> for ast::Attribute {
528542}
529543
530544// This is a rough approximation that gets us what we want.
531- impl attr:: AttrMetaMethods for Attribute {
532- fn name ( & self ) -> InternedString {
545+ impl attr:: AttrNestedMetaItemMethods for Attribute {
546+ fn check_name ( & self , name : & str ) -> bool {
547+ self . name ( ) . map_or ( false , |mi_name| & * mi_name == name)
548+ }
549+
550+ fn literal ( & self ) -> Option < & ast:: Lit > { None }
551+
552+ fn is_literal ( & self ) -> bool {
553+ match * self {
554+ Literal ( ..) => true ,
555+ _ => false ,
556+ }
557+ }
558+
559+ fn meta_item ( & self ) -> Option < & P < ast:: MetaItem > > { None }
560+
561+ fn name ( & self ) -> Option < InternedString > {
533562 match * self {
534563 Word ( ref n) | List ( ref n, _) | NameValue ( ref n, _) => {
535- token:: intern_and_get_ident ( n)
536- }
564+ Some ( token:: intern_and_get_ident ( n) )
565+ } ,
566+ _ => None
537567 }
538568 }
539569
@@ -545,7 +575,8 @@ impl attr::AttrMetaMethods for Attribute {
545575 _ => None ,
546576 }
547577 }
548- fn meta_item_list < ' a > ( & ' a self ) -> Option < & ' a [ P < ast:: MetaItem > ] > { None }
578+
579+ fn word ( & self ) -> Option < & P < ast:: MetaItem > > { None }
549580
550581 fn is_word ( & self ) -> bool {
551582 match * self {
@@ -554,12 +585,7 @@ impl attr::AttrMetaMethods for Attribute {
554585 }
555586 }
556587
557- fn is_value_str ( & self ) -> bool {
558- match * self {
559- NameValue ( ..) => true ,
560- _ => false ,
561- }
562- }
588+ fn meta_item_list < ' a > ( & ' a self ) -> Option < & ' a [ ast:: NestedMetaItem ] > { None }
563589
564590 fn is_meta_item_list ( & self ) -> bool {
565591 match * self {
@@ -2534,8 +2560,8 @@ impl Clean<Vec<Item>> for doctree::Import {
25342560 // Don't inline doc(hidden) imports so they can be stripped at a later stage.
25352561 let denied = self . vis != hir:: Public || self . attrs . iter ( ) . any ( |a| {
25362562 & a. name ( ) [ ..] == "doc" && match a. meta_item_list ( ) {
2537- Some ( l) => attr:: contains_name ( l, "no_inline" ) ||
2538- attr:: contains_name ( l, "hidden" ) ,
2563+ Some ( l) => attr:: list_contains_name ( l, "no_inline" ) ||
2564+ attr:: list_contains_name ( l, "hidden" ) ,
25392565 None => false ,
25402566 }
25412567 } ) ;
0 commit comments