X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_ast%2Fsrc%2Fattr%2Fmod.rs;h=09b08d5059c1c30e936ad6c2078abe2ede39449c;hb=67d5cc0462f33773f042dc3c5ec9bd710095b1b4;hp=990f4f8f1329f2ab2d53171088527d02491ae0d8;hpb=3baf5f8d9a453767e349c2c080a907ee4100e8df;p=rust.git diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 990f4f8f132..09b08d5059c 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -10,19 +10,18 @@ use crate::tokenstream::{DelimSpan, Spacing, TokenTree}; use crate::tokenstream::{LazyAttrTokenStream, TokenStream}; use crate::util::comments; - use rustc_data_structures::sync::WorkerLocal; use rustc_index::bit_set::GrowableBitSet; use rustc_span::source_map::BytePos; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::Span; - use std::cell::Cell; use std::iter; #[cfg(debug_assertions)] use std::ops::BitXor; #[cfg(debug_assertions)] use std::sync::atomic::{AtomicU32, Ordering}; +use thin_vec::thin_vec; pub struct MarkedAttrs(GrowableBitSet); @@ -471,12 +470,12 @@ fn from_tokens(tokens: &mut iter::Peekable) -> Option tokens.peek() { tokens.next(); - vec![PathSegment::from_ident(Ident::new(name, span))] + thin_vec![PathSegment::from_ident(Ident::new(name, span))] } else { break 'arm Path::from_ident(Ident::new(name, span)); } } else { - vec![PathSegment::path_root(span)] + thin_vec![PathSegment::path_root(span)] }; loop { if let Some(TokenTree::Token(Token { kind: token::Ident(name, _), span }, _)) = @@ -533,7 +532,7 @@ pub fn mac_args(&self, span: Span) -> MacArgs { MetaItemKind::NameValue(lit) => { let expr = P(ast::Expr { id: ast::DUMMY_NODE_ID, - kind: ast::ExprKind::Lit(lit.clone()), + kind: ast::ExprKind::Lit(lit.token_lit.clone()), span: lit.span, attrs: ast::AttrVec::new(), tokens: None, @@ -605,7 +604,7 @@ fn name_value_from_tokens( MetaItemKind::name_value_from_tokens(&mut inner_tokens.into_trees()) } Some(TokenTree::Token(token, _)) => { - Lit::from_token(&token).ok().map(MetaItemKind::NameValue) + Lit::from_token(&token).map(MetaItemKind::NameValue) } _ => None, } @@ -618,8 +617,10 @@ fn from_mac_args(args: &MacArgs) -> Option { MetaItemKind::list_from_tokens(tokens.clone()) } MacArgs::Delimited(..) => None, - MacArgs::Eq(_, MacArgsEq::Ast(expr)) => match &expr.kind { - ast::ExprKind::Lit(lit) => Some(MetaItemKind::NameValue(lit.clone())), + MacArgs::Eq(_, MacArgsEq::Ast(expr)) => match expr.kind { + ast::ExprKind::Lit(token_lit) => Some(MetaItemKind::NameValue( + Lit::from_token_lit(token_lit, expr.span).expect("token_lit in from_mac_args"), + )), _ => None, }, MacArgs::Eq(_, MacArgsEq::Hir(lit)) => Some(MetaItemKind::NameValue(lit.clone())), @@ -668,7 +669,7 @@ fn from_tokens(tokens: &mut iter::Peekable) -> Option { match tokens.peek() { Some(TokenTree::Token(token, _)) - if let Ok(lit) = Lit::from_token(token) => + if let Some(lit) = Lit::from_token(token) => { tokens.next(); return Some(NestedMetaItem::Literal(lit));