@@ -140,17 +140,14 @@ impl Attribute {
140140
141141 pub fn value_str ( & self ) -> Option < Symbol > {
142142 match & self . kind {
143- AttrKind :: Normal ( normal) => normal. item . meta_kind ( ) . and_then ( |kind| kind . value_str ( ) ) ,
143+ AttrKind :: Normal ( normal) => normal. item . value_str ( ) ,
144144 AttrKind :: DocComment ( ..) => None ,
145145 }
146146 }
147147
148148 pub fn meta_item_list ( & self ) -> Option < Vec < NestedMetaItem > > {
149149 match & self . kind {
150- AttrKind :: Normal ( normal) => match normal. item . meta_kind ( ) {
151- Some ( MetaItemKind :: List ( list) ) => Some ( list) ,
152- _ => None ,
153- } ,
150+ AttrKind :: Normal ( normal) => normal. item . meta_item_list ( ) ,
154151 AttrKind :: DocComment ( ..) => None ,
155152 }
156153 }
@@ -216,6 +213,20 @@ impl MetaItem {
216213 }
217214}
218215
216+ impl AttrArgsEq {
217+ fn value_str ( & self ) -> Option < Symbol > {
218+ match self {
219+ AttrArgsEq :: Ast ( expr) => match expr. kind {
220+ ExprKind :: Lit ( token_lit) => {
221+ LitKind :: from_token_lit ( token_lit) . ok ( ) . and_then ( |lit| lit. str ( ) )
222+ }
223+ _ => None ,
224+ } ,
225+ AttrArgsEq :: Hir ( lit) => lit. kind . str ( ) ,
226+ }
227+ }
228+ }
229+
219230impl AttrItem {
220231 pub fn span ( & self ) -> Span {
221232 self . args . span ( ) . map_or ( self . path . span , |args_span| self . path . span . to ( args_span) )
@@ -228,6 +239,22 @@ impl AttrItem {
228239 pub fn meta_kind ( & self ) -> Option < MetaItemKind > {
229240 MetaItemKind :: from_attr_args ( & self . args )
230241 }
242+
243+ fn meta_item_list ( & self ) -> Option < Vec < NestedMetaItem > > {
244+ match & self . args {
245+ AttrArgs :: Delimited ( args) if args. delim == MacDelimiter :: Parenthesis => {
246+ MetaItemKind :: list_from_tokens ( args. tokens . clone ( ) )
247+ }
248+ AttrArgs :: Delimited ( _) | AttrArgs :: Eq ( ..) | AttrArgs :: Empty => None ,
249+ }
250+ }
251+
252+ fn value_str ( & self ) -> Option < Symbol > {
253+ match & self . args {
254+ AttrArgs :: Eq ( _, args) => args. value_str ( ) ,
255+ AttrArgs :: Delimited ( _) | AttrArgs :: Empty => None ,
256+ }
257+ }
231258}
232259
233260impl Attribute {
@@ -247,13 +274,11 @@ impl Attribute {
247274 /// * `#[doc = "doc"]` returns `Some(("doc", CommentKind::Line))`.
248275 /// * `#[doc(...)]` returns `None`.
249276 pub fn doc_str_and_comment_kind ( & self ) -> Option < ( Symbol , CommentKind ) > {
250- match self . kind {
251- AttrKind :: DocComment ( kind, data) => Some ( ( data, kind) ) ,
252- AttrKind :: Normal ( ref normal) if normal. item . path == sym:: doc => normal
253- . item
254- . meta_kind ( )
255- . and_then ( |kind| kind. value_str ( ) )
256- . map ( |data| ( data, CommentKind :: Line ) ) ,
277+ match & self . kind {
278+ AttrKind :: DocComment ( kind, data) => Some ( ( * data, * kind) ) ,
279+ AttrKind :: Normal ( normal) if normal. item . path == sym:: doc => {
280+ normal. item . value_str ( ) . map ( |s| ( s, CommentKind :: Line ) )
281+ }
257282 _ => None ,
258283 }
259284 }
@@ -265,9 +290,7 @@ impl Attribute {
265290 pub fn doc_str ( & self ) -> Option < Symbol > {
266291 match & self . kind {
267292 AttrKind :: DocComment ( .., data) => Some ( * data) ,
268- AttrKind :: Normal ( normal) if normal. item . path == sym:: doc => {
269- normal. item . meta_kind ( ) . and_then ( |kind| kind. value_str ( ) )
270- }
293+ AttrKind :: Normal ( normal) if normal. item . path == sym:: doc => normal. item . value_str ( ) ,
271294 _ => None ,
272295 }
273296 }
@@ -508,15 +531,12 @@ impl MetaItem {
508531impl MetaItemKind {
509532 pub fn value_str ( & self ) -> Option < Symbol > {
510533 match self {
511- MetaItemKind :: NameValue ( v) => match v. kind {
512- LitKind :: Str ( s, _) => Some ( s) ,
513- _ => None ,
514- } ,
534+ MetaItemKind :: NameValue ( v) => v. kind . str ( ) ,
515535 _ => None ,
516536 }
517537 }
518538
519- fn list_from_tokens ( tokens : TokenStream ) -> Option < MetaItemKind > {
539+ fn list_from_tokens ( tokens : TokenStream ) -> Option < Vec < NestedMetaItem > > {
520540 let mut tokens = tokens. into_trees ( ) . peekable ( ) ;
521541 let mut result = Vec :: new ( ) ;
522542 while tokens. peek ( ) . is_some ( ) {
@@ -527,7 +547,7 @@ impl MetaItemKind {
527547 _ => return None ,
528548 }
529549 }
530- Some ( MetaItemKind :: List ( result) )
550+ Some ( result)
531551 }
532552
533553 fn name_value_from_tokens (
@@ -551,7 +571,7 @@ impl MetaItemKind {
551571 dspan : _,
552572 delim : MacDelimiter :: Parenthesis ,
553573 tokens,
554- } ) => MetaItemKind :: list_from_tokens ( tokens. clone ( ) ) ,
574+ } ) => MetaItemKind :: list_from_tokens ( tokens. clone ( ) ) . map ( MetaItemKind :: List ) ,
555575 AttrArgs :: Delimited ( ..) => None ,
556576 AttrArgs :: Eq ( _, AttrArgsEq :: Ast ( expr) ) => match expr. kind {
557577 ExprKind :: Lit ( token_lit) => {
@@ -573,7 +593,7 @@ impl MetaItemKind {
573593 Some ( TokenTree :: Delimited ( _, Delimiter :: Parenthesis , inner_tokens) ) => {
574594 let inner_tokens = inner_tokens. clone ( ) ;
575595 tokens. next ( ) ;
576- MetaItemKind :: list_from_tokens ( inner_tokens)
596+ MetaItemKind :: list_from_tokens ( inner_tokens) . map ( MetaItemKind :: List )
577597 }
578598 Some ( TokenTree :: Delimited ( ..) ) => None ,
579599 Some ( TokenTree :: Token ( Token { kind : token:: Eq , .. } , _) ) => {
0 commit comments