diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
commit | d1b2d29528b7794b41e66fc2136e395a02f8529b (patch) | |
tree | a4a17504b260206dec3cf55b2dca82929a348ac2 /compiler/rustc_ast/src/attr | |
parent | Releasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_ast/src/attr')
-rw-r--r-- | compiler/rustc_ast/src/attr/mod.rs | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 15fe29580..19a2b3017 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -2,7 +2,7 @@ use crate::ast::{AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute}; use crate::ast::{DelimArgs, Expr, ExprKind, LitKind, MetaItemLit}; -use crate::ast::{MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem, NormalAttr}; +use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem, NormalAttr}; use crate::ast::{Path, PathSegment, DUMMY_NODE_ID}; use crate::ptr::P; use crate::token::{self, CommentKind, Delimiter, Token}; @@ -196,7 +196,7 @@ impl AttrItem { fn meta_item_list(&self) -> Option<ThinVec<NestedMetaItem>> { match &self.args { - AttrArgs::Delimited(args) if args.delim == MacDelimiter::Parenthesis => { + AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => { MetaItemKind::list_from_tokens(args.tokens.clone()) } AttrArgs::Delimited(_) | AttrArgs::Eq(..) | AttrArgs::Empty => None, @@ -285,17 +285,17 @@ impl MetaItem { self.kind.value_str() } - fn from_tokens<I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItem> + fn from_tokens<'a, I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItem> where - I: Iterator<Item = TokenTree>, + I: Iterator<Item = &'a TokenTree>, { // FIXME: Share code with `parse_path`. - let path = match tokens.next().map(TokenTree::uninterpolate) { - Some(TokenTree::Token( - Token { kind: kind @ (token::Ident(..) | token::ModSep), span }, + let path = match tokens.next().map(|tt| TokenTree::uninterpolate(tt)).as_deref() { + Some(&TokenTree::Token( + Token { kind: ref kind @ (token::Ident(..) | token::ModSep), span }, _, )) => 'arm: { - let mut segments = if let token::Ident(name, _) = kind { + let mut segments = if let &token::Ident(name, _) = kind { if let Some(TokenTree::Token(Token { kind: token::ModSep, .. }, _)) = tokens.peek() { @@ -308,8 +308,8 @@ impl MetaItem { thin_vec![PathSegment::path_root(span)] }; loop { - if let Some(TokenTree::Token(Token { kind: token::Ident(name, _), span }, _)) = - tokens.next().map(TokenTree::uninterpolate) + if let Some(&TokenTree::Token(Token { kind: token::Ident(name, _), span }, _)) = + tokens.next().map(|tt| TokenTree::uninterpolate(tt)).as_deref() { segments.push(PathSegment::from_ident(Ident::new(name, span))); } else { @@ -326,7 +326,7 @@ impl MetaItem { let span = span.with_hi(segments.last().unwrap().ident.span.hi()); Path { span, segments, tokens: None } } - Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match &*nt { + Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match &**nt { token::Nonterminal::NtMeta(item) => return item.meta(item.path.span), token::Nonterminal::NtPath(path) => (**path).clone(), _ => return None, @@ -354,7 +354,7 @@ impl MetaItemKind { } fn list_from_tokens(tokens: TokenStream) -> Option<ThinVec<NestedMetaItem>> { - let mut tokens = tokens.into_trees().peekable(); + let mut tokens = tokens.trees().peekable(); let mut result = ThinVec::new(); while tokens.peek().is_some() { let item = NestedMetaItem::from_tokens(&mut tokens)?; @@ -367,12 +367,12 @@ impl MetaItemKind { Some(result) } - fn name_value_from_tokens( - tokens: &mut impl Iterator<Item = TokenTree>, + fn name_value_from_tokens<'a>( + tokens: &mut impl Iterator<Item = &'a TokenTree>, ) -> Option<MetaItemKind> { match tokens.next() { Some(TokenTree::Delimited(_, Delimiter::Invisible, inner_tokens)) => { - MetaItemKind::name_value_from_tokens(&mut inner_tokens.into_trees()) + MetaItemKind::name_value_from_tokens(&mut inner_tokens.trees()) } Some(TokenTree::Token(token, _)) => { MetaItemLit::from_token(&token).map(MetaItemKind::NameValue) @@ -381,8 +381,8 @@ impl MetaItemKind { } } - fn from_tokens( - tokens: &mut iter::Peekable<impl Iterator<Item = TokenTree>>, + fn from_tokens<'a>( + tokens: &mut iter::Peekable<impl Iterator<Item = &'a TokenTree>>, ) -> Option<MetaItemKind> { match tokens.peek() { Some(TokenTree::Delimited(_, Delimiter::Parenthesis, inner_tokens)) => { @@ -402,11 +402,9 @@ impl MetaItemKind { fn from_attr_args(args: &AttrArgs) -> Option<MetaItemKind> { match args { AttrArgs::Empty => Some(MetaItemKind::Word), - AttrArgs::Delimited(DelimArgs { - dspan: _, - delim: MacDelimiter::Parenthesis, - tokens, - }) => MetaItemKind::list_from_tokens(tokens.clone()).map(MetaItemKind::List), + AttrArgs::Delimited(DelimArgs { dspan: _, delim: Delimiter::Parenthesis, tokens }) => { + MetaItemKind::list_from_tokens(tokens.clone()).map(MetaItemKind::List) + } AttrArgs::Delimited(..) => None, AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => match expr.kind { ExprKind::Lit(token_lit) => { @@ -501,9 +499,9 @@ impl NestedMetaItem { self.meta_item().is_some() } - fn from_tokens<I>(tokens: &mut iter::Peekable<I>) -> Option<NestedMetaItem> + fn from_tokens<'a, I>(tokens: &mut iter::Peekable<I>) -> Option<NestedMetaItem> where - I: Iterator<Item = TokenTree>, + I: Iterator<Item = &'a TokenTree>, { match tokens.peek() { Some(TokenTree::Token(token, _)) @@ -513,9 +511,8 @@ impl NestedMetaItem { return Some(NestedMetaItem::Lit(lit)); } Some(TokenTree::Delimited(_, Delimiter::Invisible, inner_tokens)) => { - let inner_tokens = inner_tokens.clone(); tokens.next(); - return NestedMetaItem::from_tokens(&mut inner_tokens.into_trees().peekable()); + return NestedMetaItem::from_tokens(&mut inner_tokens.trees().peekable()); } _ => {} } @@ -579,7 +576,7 @@ pub fn mk_attr_nested_word( let path = Path::from_ident(outer_ident); let attr_args = AttrArgs::Delimited(DelimArgs { dspan: DelimSpan::from_single(span), - delim: MacDelimiter::Parenthesis, + delim: Delimiter::Parenthesis, tokens: inner_tokens, }); mk_attr(g, style, path, attr_args, span) |