@@ -305,8 +305,8 @@ impl MetaItem {
305305 if let [ PathSegment { ident, .. } ] = self . path . segments [ ..] { Some ( ident) } else { None }
306306 }
307307
308- pub fn name_or_empty ( & self ) -> Symbol {
309- self . ident ( ) . unwrap_or_else ( Ident :: empty ) . name
308+ pub fn name ( & self ) -> Option < Symbol > {
309+ self . ident ( ) . map ( |ident| ident . name )
310310 }
311311
312312 pub fn has_name ( & self , name : Symbol ) -> bool {
@@ -511,13 +511,14 @@ impl MetaItemInner {
511511 }
512512 }
513513
514- /// For a single-segment meta item, returns its name ; otherwise, returns `None`.
514+ /// For a single-segment meta item, returns its identifier ; otherwise, returns `None`.
515515 pub fn ident ( & self ) -> Option < Ident > {
516516 self . meta_item ( ) . and_then ( |meta_item| meta_item. ident ( ) )
517517 }
518518
519- pub fn name_or_empty ( & self ) -> Symbol {
520- self . ident ( ) . unwrap_or_else ( Ident :: empty) . name
519+ /// For a single-segment meta item, returns its name; otherwise, returns `None`.
520+ pub fn name ( & self ) -> Option < Symbol > {
521+ self . ident ( ) . map ( |ident| ident. name )
521522 }
522523
523524 /// Returns `true` if this list item is a MetaItem with a name of `name`.
@@ -738,9 +739,9 @@ pub trait AttributeExt: Debug {
738739 fn id ( & self ) -> AttrId ;
739740
740741 /// For a single-segment attribute (i.e., `#[attr]` and not `#[path::atrr]`),
741- /// return the name of the attribute, else return the empty identifier .
742- fn name_or_empty ( & self ) -> Symbol {
743- self . ident ( ) . unwrap_or_else ( Ident :: empty ) . name
742+ /// return the name of the attribute; otherwise, returns `None` .
743+ fn name ( & self ) -> Option < Symbol > {
744+ self . ident ( ) . map ( |ident| ident . name )
744745 }
745746
746747 /// Get the meta item list, `#[attr(meta item list)]`
@@ -752,7 +753,7 @@ pub trait AttributeExt: Debug {
752753 /// Gets the span of the value literal, as string, when using `#[attr = value]`
753754 fn value_span ( & self ) -> Option < Span > ;
754755
755- /// For a single-segment attribute, returns its name ; otherwise, returns `None`.
756+ /// For a single-segment attribute, returns its ident ; otherwise, returns `None`.
756757 fn ident ( & self ) -> Option < Ident > ;
757758
758759 /// Checks whether the path of this attribute matches the name.
@@ -770,6 +771,11 @@ pub trait AttributeExt: Debug {
770771 self . ident ( ) . map ( |x| x. name == name) . unwrap_or ( false )
771772 }
772773
774+ #[ inline]
775+ fn has_any_name ( & self , names : & [ Symbol ] ) -> bool {
776+ names. iter ( ) . any ( |& name| self . has_name ( name) )
777+ }
778+
773779 /// get the span of the entire attribute
774780 fn span ( & self ) -> Span ;
775781
@@ -813,8 +819,8 @@ impl Attribute {
813819 AttributeExt :: id ( self )
814820 }
815821
816- pub fn name_or_empty ( & self ) -> Symbol {
817- AttributeExt :: name_or_empty ( self )
822+ pub fn name ( & self ) -> Option < Symbol > {
823+ AttributeExt :: name ( self )
818824 }
819825
820826 pub fn meta_item_list ( & self ) -> Option < ThinVec < MetaItemInner > > {
@@ -846,6 +852,11 @@ impl Attribute {
846852 AttributeExt :: has_name ( self , name)
847853 }
848854
855+ #[ inline]
856+ pub fn has_any_name ( & self , names : & [ Symbol ] ) -> bool {
857+ AttributeExt :: has_any_name ( self , names)
858+ }
859+
849860 pub fn span ( & self ) -> Span {
850861 AttributeExt :: span ( self )
851862 }
0 commit comments