Change return type of Attribute::tokens
.
The `AttrTokenStream` is always immediately turned into a `TokenStream`.
This commit is contained in:
parent
a56d345490
commit
208ca93cda
@ -7,7 +7,6 @@ use crate::ast::{MacArgs, MacArgsEq, MacDelimiter, MetaItem, MetaItemKind, Neste
|
|||||||
use crate::ast::{Path, PathSegment};
|
use crate::ast::{Path, PathSegment};
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::token::{self, CommentKind, Delimiter, Token};
|
use crate::token::{self, CommentKind, Delimiter, Token};
|
||||||
use crate::tokenstream::{AttrTokenStream, AttrTokenTree};
|
|
||||||
use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
|
use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
|
||||||
use crate::tokenstream::{LazyTokenStream, TokenStream};
|
use crate::tokenstream::{LazyTokenStream, TokenStream};
|
||||||
use crate::util::comments;
|
use crate::util::comments;
|
||||||
@ -296,19 +295,18 @@ impl Attribute {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tokens(&self) -> AttrTokenStream {
|
pub fn tokens(&self) -> TokenStream {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
AttrKind::Normal(ref normal) => normal
|
AttrKind::Normal(ref normal) => normal
|
||||||
.tokens
|
.tokens
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self))
|
.unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self))
|
||||||
.create_token_stream(),
|
.create_token_stream()
|
||||||
AttrKind::DocComment(comment_kind, data) => {
|
.to_tokenstream(),
|
||||||
AttrTokenStream::new(vec![AttrTokenTree::Token(
|
AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token(
|
||||||
Token::new(token::DocComment(comment_kind, self.style, data), self.span),
|
Token::new(token::DocComment(comment_kind, self.style, data), self.span),
|
||||||
Spacing::Alone,
|
Spacing::Alone,
|
||||||
)])
|
)]),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ impl AttrTokenStream {
|
|||||||
|
|
||||||
let mut builder = TokenStreamBuilder::new();
|
let mut builder = TokenStreamBuilder::new();
|
||||||
for inner_attr in inner_attrs {
|
for inner_attr in inner_attrs {
|
||||||
builder.push(inner_attr.tokens().to_tokenstream());
|
builder.push(inner_attr.tokens());
|
||||||
}
|
}
|
||||||
builder.push(delim_tokens.clone());
|
builder.push(delim_tokens.clone());
|
||||||
*tree = TokenTree::Delimited(*span, *delim, builder.build());
|
*tree = TokenTree::Delimited(*span, *delim, builder.build());
|
||||||
@ -273,7 +273,7 @@ impl AttrTokenStream {
|
|||||||
let mut flat: SmallVec<[_; 1]> = SmallVec::new();
|
let mut flat: SmallVec<[_; 1]> = SmallVec::new();
|
||||||
for attr in outer_attrs {
|
for attr in outer_attrs {
|
||||||
// FIXME: Make this more efficient
|
// 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.extend(target_tokens);
|
||||||
flat.into_iter()
|
flat.into_iter()
|
||||||
|
@ -388,7 +388,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
attr: &Attribute,
|
attr: &Attribute,
|
||||||
(item, item_span): (ast::AttrItem, Span),
|
(item, item_span): (ast::AttrItem, Span),
|
||||||
) -> Attribute {
|
) -> 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)]`
|
// We are taking an attribute of the form `#[cfg_attr(pred, attr)]`
|
||||||
// and producing an attribute of the form `#[attr]`. We
|
// and producing an attribute of the form `#[attr]`. We
|
||||||
|
Loading…
x
Reference in New Issue
Block a user