@@ -305,8 +305,8 @@ impl MetaItem {
305
305
if let [ PathSegment { ident, .. } ] = self . path . segments [ ..] { Some ( ident) } else { None }
306
306
}
307
307
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 )
310
310
}
311
311
312
312
pub fn has_name ( & self , name : Symbol ) -> bool {
@@ -511,13 +511,14 @@ impl MetaItemInner {
511
511
}
512
512
}
513
513
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`.
515
515
pub fn ident ( & self ) -> Option < Ident > {
516
516
self . meta_item ( ) . and_then ( |meta_item| meta_item. ident ( ) )
517
517
}
518
518
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 )
521
522
}
522
523
523
524
/// Returns `true` if this list item is a MetaItem with a name of `name`.
@@ -738,9 +739,9 @@ pub trait AttributeExt: Debug {
738
739
fn id ( & self ) -> AttrId ;
739
740
740
741
/// 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 )
744
745
}
745
746
746
747
/// Get the meta item list, `#[attr(meta item list)]`
@@ -752,7 +753,7 @@ pub trait AttributeExt: Debug {
752
753
/// Gets the span of the value literal, as string, when using `#[attr = value]`
753
754
fn value_span ( & self ) -> Option < Span > ;
754
755
755
- /// For a single-segment attribute, returns its name ; otherwise, returns `None`.
756
+ /// For a single-segment attribute, returns its ident ; otherwise, returns `None`.
756
757
fn ident ( & self ) -> Option < Ident > ;
757
758
758
759
/// Checks whether the path of this attribute matches the name.
@@ -770,6 +771,11 @@ pub trait AttributeExt: Debug {
770
771
self . ident ( ) . map ( |x| x. name == name) . unwrap_or ( false )
771
772
}
772
773
774
+ #[ inline]
775
+ fn has_any_name ( & self , names : & [ Symbol ] ) -> bool {
776
+ names. iter ( ) . any ( |& name| self . has_name ( name) )
777
+ }
778
+
773
779
/// get the span of the entire attribute
774
780
fn span ( & self ) -> Span ;
775
781
@@ -813,8 +819,8 @@ impl Attribute {
813
819
AttributeExt :: id ( self )
814
820
}
815
821
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 )
818
824
}
819
825
820
826
pub fn meta_item_list ( & self ) -> Option < ThinVec < MetaItemInner > > {
@@ -846,6 +852,11 @@ impl Attribute {
846
852
AttributeExt :: has_name ( self , name)
847
853
}
848
854
855
+ #[ inline]
856
+ pub fn has_any_name ( & self , names : & [ Symbol ] ) -> bool {
857
+ AttributeExt :: has_any_name ( self , names)
858
+ }
859
+
849
860
pub fn span ( & self ) -> Span {
850
861
AttributeExt :: span ( self )
851
862
}
0 commit comments