diff options
Diffstat (limited to 'compiler/rustc_ast/src/attr/mod.rs')
| -rw-r--r-- | compiler/rustc_ast/src/attr/mod.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 19c7c479f04..6a54cb4766b 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -234,10 +234,7 @@ impl MetaItem { } pub fn is_word(&self) -> bool { - match self.kind { - MetaItemKind::Word => true, - _ => false, - } + matches!(self.kind, MetaItemKind::Word) } pub fn has_name(&self, name: Symbol) -> bool { @@ -479,7 +476,7 @@ impl MetaItemKind { pub fn mac_args(&self, span: Span) -> MacArgs { match self { MetaItemKind::Word => MacArgs::Empty, - MetaItemKind::NameValue(lit) => MacArgs::Eq(span, lit.token_tree().into()), + MetaItemKind::NameValue(lit) => MacArgs::Eq(span, lit.to_token()), MetaItemKind::List(list) => { let mut tts = Vec::new(); for (i, item) in list.iter().enumerate() { @@ -501,7 +498,10 @@ impl MetaItemKind { match *self { MetaItemKind::Word => vec![], MetaItemKind::NameValue(ref lit) => { - vec![TokenTree::token(token::Eq, span).into(), lit.token_tree().into()] + vec![ + TokenTree::token(token::Eq, span).into(), + TokenTree::Token(lit.to_token()).into(), + ] } MetaItemKind::List(ref list) => { let mut tokens = Vec::new(); @@ -557,10 +557,7 @@ impl MetaItemKind { MetaItemKind::list_from_tokens(tokens.clone()) } MacArgs::Delimited(..) => None, - MacArgs::Eq(_, tokens) => { - assert!(tokens.len() == 1); - MetaItemKind::name_value_from_tokens(&mut tokens.trees()) - } + MacArgs::Eq(_, token) => Lit::from_token(token).ok().map(MetaItemKind::NameValue), MacArgs::Empty => Some(MetaItemKind::Word), } } @@ -595,7 +592,7 @@ impl NestedMetaItem { fn token_trees_and_spacings(&self) -> Vec<TreeAndSpacing> { match *self { NestedMetaItem::MetaItem(ref item) => item.token_trees_and_spacings(), - NestedMetaItem::Literal(ref lit) => vec![lit.token_tree().into()], + NestedMetaItem::Literal(ref lit) => vec![TokenTree::Token(lit.to_token()).into()], } } |
