Skip to content

Commit

Permalink
Change Lit::tokens() to Lit::token_tree().
Browse files Browse the repository at this point in the history
Because most of the call sites have an easier time working with a
`TokenTree` instead of a `TokenStream`.
  • Loading branch information
nnethercote committed Oct 18, 2019
1 parent a6eef29 commit 212ae58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/libsyntax/attr/mod.rs
Expand Up @@ -541,9 +541,10 @@ impl MetaItemKind {
match *self {
MetaItemKind::Word => TokenStream::default(),
MetaItemKind::NameValue(ref lit) => {
let mut vec = vec![TokenTree::token(token::Eq, span).into()];
lit.tokens().append_to_tree_and_joint_vec(&mut vec);
TokenStream::new(vec)
TokenStream::new(vec![
TokenTree::token(token::Eq, span).into(),
lit.token_tree().into(),
])
}
MetaItemKind::List(ref list) => {
let mut tokens = Vec::new();
Expand Down Expand Up @@ -606,7 +607,7 @@ impl NestedMetaItem {
fn tokens(&self) -> TokenStream {
match *self {
NestedMetaItem::MetaItem(ref item) => item.tokens(),
NestedMetaItem::Literal(ref lit) => lit.tokens(),
NestedMetaItem::Literal(ref lit) => lit.token_tree().into(),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/parse/literal.rs
Expand Up @@ -3,7 +3,7 @@
use crate::ast::{self, Lit, LitKind};
use crate::parse::token::{self, Token};
use crate::symbol::{kw, sym, Symbol};
use crate::tokenstream::{TokenStream, TokenTree};
use crate::tokenstream::TokenTree;

use log::debug;
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -216,13 +216,13 @@ impl Lit {
Lit { token: kind.to_lit_token(), kind, span }
}

/// Losslessly convert an AST literal into a token stream.
crate fn tokens(&self) -> TokenStream {
/// Losslessly convert an AST literal into a token tree.
crate fn token_tree(&self) -> TokenTree {
let token = match self.token.kind {
token::Bool => token::Ident(self.token.symbol, false),
_ => token::Literal(self.token),
};
TokenTree::token(token, self.span).into()
TokenTree::token(token, self.span)
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/libsyntax/parse/parser/attr.rs
Expand Up @@ -6,7 +6,6 @@ use crate::tokenstream::{TokenStream, TokenTree};
use crate::source_map::Span;

use log::debug;
use smallvec::smallvec;

#[derive(Debug)]
enum InnerAttributeParsePolicy<'a> {
Expand Down Expand Up @@ -193,15 +192,15 @@ impl<'a> Parser<'a> {
is_interpolated_expr = true;
}
}
let tokens = if is_interpolated_expr {
let token_tree = if is_interpolated_expr {
// We need to accept arbitrary interpolated expressions to continue
// supporting things like `doc = $expr` that work on stable.
// Non-literal interpolated expressions are rejected after expansion.
self.parse_token_tree().into()
self.parse_token_tree()
} else {
self.parse_unsuffixed_lit()?.tokens()
self.parse_unsuffixed_lit()?.token_tree()
};
TokenStream::from_streams(smallvec![eq.into(), tokens])
TokenStream::new(vec![eq.into(), token_tree.into()])
} else {
TokenStream::default()
};
Expand Down

0 comments on commit 212ae58

Please sign in to comment.