Skip to content

Commit

Permalink
Merge pull request #339 from dtolnay/push
Browse files Browse the repository at this point in the history
Rename the two different token push methods
  • Loading branch information
dtolnay authored Jul 25, 2022
2 parents 682d119 + c39fd4c commit f66898b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl TokenStream {
mem::replace(Rc::make_mut(&mut self.inner), Vec::new())
}

fn push_token(&mut self, token: TokenTree) {
fn push_token_from_proc_macro(&mut self, token: TokenTree) {
// https://github.com/dtolnay/proc-macro2/issues/235
match token {
#[cfg(not(no_bind_by_move_pattern_guard))]
Expand Down Expand Up @@ -147,7 +147,7 @@ impl TokenStreamBuilder {
}
}

pub fn push(&mut self, tt: TokenTree) {
pub fn push_token_from_parser(&mut self, tt: TokenTree) {
self.inner.push(tt);
}

Expand Down Expand Up @@ -247,7 +247,7 @@ impl From<TokenStream> for proc_macro::TokenStream {
impl From<TokenTree> for TokenStream {
fn from(tree: TokenTree) -> TokenStream {
let mut stream = TokenStream::new();
stream.push_token(tree);
stream.push_token_from_proc_macro(tree);
stream
}
}
Expand All @@ -274,7 +274,9 @@ impl FromIterator<TokenStream> for TokenStream {

impl Extend<TokenTree> for TokenStream {
fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, tokens: I) {
tokens.into_iter().for_each(|token| self.push_token(token));
tokens
.into_iter()
.for_each(|token| self.push_token_from_proc_macro(token));
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
hi: input.off,
});
trees = outer;
trees.push(TokenTree::Group(crate::Group::_new_stable(g)));
trees.push_token_from_parser(TokenTree::Group(crate::Group::_new_stable(g)));
} else {
let (rest, mut tt) = match leaf_token(input) {
Ok((rest, tt)) => (rest, tt),
Expand All @@ -229,7 +229,7 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
#[cfg(span_locations)]
hi: rest.off,
}));
trees.push(tt);
trees.push_token_from_parser(tt);
input = rest;
}
}
Expand Down Expand Up @@ -808,12 +808,12 @@ fn doc_comment<'a>(input: Cursor<'a>, trees: &mut TokenStreamBuilder) -> PResult

let mut pound = Punct::new('#', Spacing::Alone);
pound.set_span(span);
trees.push(TokenTree::Punct(pound));
trees.push_token_from_parser(TokenTree::Punct(pound));

if inner {
let mut bang = Punct::new('!', Spacing::Alone);
bang.set_span(span);
trees.push(TokenTree::Punct(bang));
trees.push_token_from_parser(TokenTree::Punct(bang));
}

let doc_ident = crate::Ident::new("doc", span);
Expand All @@ -822,13 +822,13 @@ fn doc_comment<'a>(input: Cursor<'a>, trees: &mut TokenStreamBuilder) -> PResult
let mut literal = crate::Literal::string(comment);
literal.set_span(span);
let mut bracketed = TokenStreamBuilder::with_capacity(3);
bracketed.push(TokenTree::Ident(doc_ident));
bracketed.push(TokenTree::Punct(equal));
bracketed.push(TokenTree::Literal(literal));
bracketed.push_token_from_parser(TokenTree::Ident(doc_ident));
bracketed.push_token_from_parser(TokenTree::Punct(equal));
bracketed.push_token_from_parser(TokenTree::Literal(literal));
let group = Group::new(Delimiter::Bracket, bracketed.build());
let mut group = crate::Group::_new_stable(group);
group.set_span(span);
trees.push(TokenTree::Group(group));
trees.push_token_from_parser(TokenTree::Group(group));

Ok((rest, ()))
}
Expand Down

0 comments on commit f66898b

Please sign in to comment.