Skip to content

Commit 212ae58

Browse files
committed
Change Lit::tokens() to Lit::token_tree().
Because most of the call sites have an easier time working with a `TokenTree` instead of a `TokenStream`.
1 parent a6eef29 commit 212ae58

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/libsyntax/attr/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,10 @@ impl MetaItemKind {
541541
match *self {
542542
MetaItemKind::Word => TokenStream::default(),
543543
MetaItemKind::NameValue(ref lit) => {
544-
let mut vec = vec![TokenTree::token(token::Eq, span).into()];
545-
lit.tokens().append_to_tree_and_joint_vec(&mut vec);
546-
TokenStream::new(vec)
544+
TokenStream::new(vec![
545+
TokenTree::token(token::Eq, span).into(),
546+
lit.token_tree().into(),
547+
])
547548
}
548549
MetaItemKind::List(ref list) => {
549550
let mut tokens = Vec::new();
@@ -606,7 +607,7 @@ impl NestedMetaItem {
606607
fn tokens(&self) -> TokenStream {
607608
match *self {
608609
NestedMetaItem::MetaItem(ref item) => item.tokens(),
609-
NestedMetaItem::Literal(ref lit) => lit.tokens(),
610+
NestedMetaItem::Literal(ref lit) => lit.token_tree().into(),
610611
}
611612
}
612613

src/libsyntax/parse/literal.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::ast::{self, Lit, LitKind};
44
use crate::parse::token::{self, Token};
55
use crate::symbol::{kw, sym, Symbol};
6-
use crate::tokenstream::{TokenStream, TokenTree};
6+
use crate::tokenstream::TokenTree;
77

88
use log::debug;
99
use rustc_data_structures::sync::Lrc;
@@ -216,13 +216,13 @@ impl Lit {
216216
Lit { token: kind.to_lit_token(), kind, span }
217217
}
218218

219-
/// Losslessly convert an AST literal into a token stream.
220-
crate fn tokens(&self) -> TokenStream {
219+
/// Losslessly convert an AST literal into a token tree.
220+
crate fn token_tree(&self) -> TokenTree {
221221
let token = match self.token.kind {
222222
token::Bool => token::Ident(self.token.symbol, false),
223223
_ => token::Literal(self.token),
224224
};
225-
TokenTree::token(token, self.span).into()
225+
TokenTree::token(token, self.span)
226226
}
227227
}
228228

src/libsyntax/parse/parser/attr.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::tokenstream::{TokenStream, TokenTree};
66
use crate::source_map::Span;
77

88
use log::debug;
9-
use smallvec::smallvec;
109

1110
#[derive(Debug)]
1211
enum InnerAttributeParsePolicy<'a> {
@@ -193,15 +192,15 @@ impl<'a> Parser<'a> {
193192
is_interpolated_expr = true;
194193
}
195194
}
196-
let tokens = if is_interpolated_expr {
195+
let token_tree = if is_interpolated_expr {
197196
// We need to accept arbitrary interpolated expressions to continue
198197
// supporting things like `doc = $expr` that work on stable.
199198
// Non-literal interpolated expressions are rejected after expansion.
200-
self.parse_token_tree().into()
199+
self.parse_token_tree()
201200
} else {
202-
self.parse_unsuffixed_lit()?.tokens()
201+
self.parse_unsuffixed_lit()?.token_tree()
203202
};
204-
TokenStream::from_streams(smallvec![eq.into(), tokens])
203+
TokenStream::new(vec![eq.into(), token_tree.into()])
205204
} else {
206205
TokenStream::default()
207206
};

0 commit comments

Comments
 (0)