@@ -115,6 +115,10 @@ impl NestedMetaItem {
115115 pub fn is_meta_item_list ( & self ) -> bool {
116116 self . meta_item_list ( ) . is_some ( )
117117 }
118+
119+ pub fn name_value_literal_span ( & self ) -> Option < Span > {
120+ self . meta_item ( ) ?. name_value_literal_span ( )
121+ }
118122}
119123
120124impl Attribute {
@@ -175,6 +179,22 @@ impl Attribute {
175179 pub fn is_value_str ( & self ) -> bool {
176180 self . value_str ( ) . is_some ( )
177181 }
182+
183+ /// This is used in case you want the value span instead of the whole attribute. Example:
184+ ///
185+ /// ```text
186+ /// #[doc(alias = "foo")]
187+ /// ```
188+ ///
189+ /// In here, it'll return a span for `"foo"`.
190+ pub fn name_value_literal_span ( & self ) -> Option < Span > {
191+ match self . kind {
192+ AttrKind :: Normal ( ref item, _) => {
193+ item. meta ( self . span ) . and_then ( |meta| meta. name_value_literal_span ( ) )
194+ }
195+ AttrKind :: DocComment ( ..) => None ,
196+ }
197+ }
178198}
179199
180200impl MetaItem {
@@ -227,6 +247,17 @@ impl MetaItem {
227247 pub fn is_value_str ( & self ) -> bool {
228248 self . value_str ( ) . is_some ( )
229249 }
250+
251+ /// This is used in case you want the value span instead of the whole attribute. Example:
252+ ///
253+ /// ```text
254+ /// #[doc(alias = "foo")]
255+ /// ```
256+ ///
257+ /// In here, it'll return a span for `"foo"`.
258+ pub fn name_value_literal_span ( & self ) -> Option < Span > {
259+ Some ( self . name_value_literal ( ) ?. span )
260+ }
230261}
231262
232263impl AttrItem {
0 commit comments