about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-09-09 16:23:39 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-09-09 16:25:31 +1000
commit208ca93cdad849e2659effbee1bfb0ece639f4a8 (patch)
tree7f12ad2cc5899efa61b3ee3e86fd32df894dd28b
parenta56d345490ed68ab57cf1854dd8978fefc9862d0 (diff)
downloadrust-208ca93cdad849e2659effbee1bfb0ece639f4a8.tar.gz
rust-208ca93cdad849e2659effbee1bfb0ece639f4a8.zip
Change return type of `Attribute::tokens`.
The `AttrTokenStream` is always immediately turned into a `TokenStream`.
-rw-r--r--compiler/rustc_ast/src/attr/mod.rs16
-rw-r--r--compiler/rustc_ast/src/tokenstream.rs4
-rw-r--r--compiler/rustc_expand/src/config.rs2
3 files changed, 10 insertions, 12 deletions
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs
index e0bb4753932..8f1d7a71f15 100644
--- a/compiler/rustc_ast/src/attr/mod.rs
+++ b/compiler/rustc_ast/src/attr/mod.rs
@@ -7,7 +7,6 @@ use crate::ast::{MacArgs, MacArgsEq, MacDelimiter, MetaItem, MetaItemKind, Neste
 use crate::ast::{Path, PathSegment};
 use crate::ptr::P;
 use crate::token::{self, CommentKind, Delimiter, Token};
-use crate::tokenstream::{AttrTokenStream, AttrTokenTree};
 use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
 use crate::tokenstream::{LazyTokenStream, TokenStream};
 use crate::util::comments;
@@ -296,19 +295,18 @@ impl Attribute {
         }
     }
 
-    pub fn tokens(&self) -> AttrTokenStream {
+    pub fn tokens(&self) -> TokenStream {
         match self.kind {
             AttrKind::Normal(ref normal) => normal
                 .tokens
                 .as_ref()
                 .unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self))
-                .create_token_stream(),
-            AttrKind::DocComment(comment_kind, data) => {
-                AttrTokenStream::new(vec![AttrTokenTree::Token(
-                    Token::new(token::DocComment(comment_kind, self.style, data), self.span),
-                    Spacing::Alone,
-                )])
-            }
+                .create_token_stream()
+                .to_tokenstream(),
+            AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token(
+                Token::new(token::DocComment(comment_kind, self.style, data), self.span),
+                Spacing::Alone,
+            )]),
         }
     }
 }
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs
index 4088e50fbe2..231bd000db0 100644
--- a/compiler/rustc_ast/src/tokenstream.rs
+++ b/compiler/rustc_ast/src/tokenstream.rs
@@ -255,7 +255,7 @@ impl AttrTokenStream {
 
                                 let mut builder = TokenStreamBuilder::new();
                                 for inner_attr in inner_attrs {
-                                    builder.push(inner_attr.tokens().to_tokenstream());
+                                    builder.push(inner_attr.tokens());
                                 }
                                 builder.push(delim_tokens.clone());
                                 *tree = TokenTree::Delimited(*span, *delim, builder.build());
@@ -273,7 +273,7 @@ impl AttrTokenStream {
                     let mut flat: SmallVec<[_; 1]> = SmallVec::new();
                     for attr in outer_attrs {
                         // FIXME: Make this more efficient
-                        flat.extend(attr.tokens().to_tokenstream().0.clone().iter().cloned());
+                        flat.extend(attr.tokens().0.clone().iter().cloned());
                     }
                     flat.extend(target_tokens);
                     flat.into_iter()
diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs
index 5d78a4a59ec..43a1a7caa2f 100644
--- a/compiler/rustc_expand/src/config.rs
+++ b/compiler/rustc_expand/src/config.rs
@@ -388,7 +388,7 @@ impl<'a> StripUnconfigured<'a> {
         attr: &Attribute,
         (item, item_span): (ast::AttrItem, Span),
     ) -> Attribute {
-        let orig_tokens = attr.tokens().to_tokenstream();
+        let orig_tokens = attr.tokens();
 
         // We are taking an attribute of the form `#[cfg_attr(pred, attr)]`
         // and producing an attribute of the form `#[attr]`. We