Skip to content

Commit 208ca93

Browse files
committed
Change return type of Attribute::tokens.
The `AttrTokenStream` is always immediately turned into a `TokenStream`.
1 parent a56d345 commit 208ca93

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::ast::{MacArgs, MacArgsEq, MacDelimiter, MetaItem, MetaItemKind, Neste
77
use crate::ast::{Path, PathSegment};
88
use crate::ptr::P;
99
use crate::token::{self, CommentKind, Delimiter, Token};
10-
use crate::tokenstream::{AttrTokenStream, AttrTokenTree};
1110
use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
1211
use crate::tokenstream::{LazyTokenStream, TokenStream};
1312
use crate::util::comments;
@@ -296,19 +295,18 @@ impl Attribute {
296295
}
297296
}
298297

299-
pub fn tokens(&self) -> AttrTokenStream {
298+
pub fn tokens(&self) -> TokenStream {
300299
match self.kind {
301300
AttrKind::Normal(ref normal) => normal
302301
.tokens
303302
.as_ref()
304303
.unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self))
305-
.create_token_stream(),
306-
AttrKind::DocComment(comment_kind, data) => {
307-
AttrTokenStream::new(vec![AttrTokenTree::Token(
308-
Token::new(token::DocComment(comment_kind, self.style, data), self.span),
309-
Spacing::Alone,
310-
)])
311-
}
304+
.create_token_stream()
305+
.to_tokenstream(),
306+
AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token(
307+
Token::new(token::DocComment(comment_kind, self.style, data), self.span),
308+
Spacing::Alone,
309+
)]),
312310
}
313311
}
314312
}

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl AttrTokenStream {
255255

256256
let mut builder = TokenStreamBuilder::new();
257257
for inner_attr in inner_attrs {
258-
builder.push(inner_attr.tokens().to_tokenstream());
258+
builder.push(inner_attr.tokens());
259259
}
260260
builder.push(delim_tokens.clone());
261261
*tree = TokenTree::Delimited(*span, *delim, builder.build());
@@ -273,7 +273,7 @@ impl AttrTokenStream {
273273
let mut flat: SmallVec<[_; 1]> = SmallVec::new();
274274
for attr in outer_attrs {
275275
// FIXME: Make this more efficient
276-
flat.extend(attr.tokens().to_tokenstream().0.clone().iter().cloned());
276+
flat.extend(attr.tokens().0.clone().iter().cloned());
277277
}
278278
flat.extend(target_tokens);
279279
flat.into_iter()

compiler/rustc_expand/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'a> StripUnconfigured<'a> {
388388
attr: &Attribute,
389389
(item, item_span): (ast::AttrItem, Span),
390390
) -> Attribute {
391-
let orig_tokens = attr.tokens().to_tokenstream();
391+
let orig_tokens = attr.tokens();
392392

393393
// We are taking an attribute of the form `#[cfg_attr(pred, attr)]`
394394
// and producing an attribute of the form `#[attr]`. We

0 commit comments

Comments
 (0)