Skip to content

Commit

Permalink
Reduce visibility of fallback TokenStream's field
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 27, 2021
1 parent 6f4dc99 commit 6d9a579
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn unforce() {

#[derive(Clone)]
pub(crate) struct TokenStream {
pub(crate) inner: Vec<TokenTree>,
inner: Vec<TokenTree>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -108,6 +108,12 @@ impl TokenStream {
}
}

impl From<Vec<TokenTree>> for TokenStream {
fn from(inner: Vec<TokenTree>) -> Self {
TokenStream { inner }
}
}

// Nonrecursive to prevent stack overflow.
impl Drop for TokenStream {
fn drop(&mut self) {
Expand Down
6 changes: 3 additions & 3 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
let first = match input.bytes().next() {
Some(first) => first,
None => match stack.last() {
None => return Ok(TokenStream { inner: trees }),
None => return Ok(TokenStream::from(trees)),
#[cfg(span_locations)]
Some((lo, _frame)) => {
return Err(LexError {
Expand Down Expand Up @@ -209,7 +209,7 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
return Err(lex_error(input));
}
input = input.advance(1);
let mut g = Group::new(open_delimiter, TokenStream { inner: trees });
let mut g = Group::new(open_delimiter, TokenStream::from(trees));
g.set_span(Span {
#[cfg(span_locations)]
lo,
Expand Down Expand Up @@ -819,7 +819,7 @@ fn doc_comment(input: Cursor) -> PResult<Vec<TokenTree>> {
for tt in &mut stream {
tt.set_span(span);
}
let group = Group::new(Delimiter::Bracket, TokenStream { inner: stream });
let group = Group::new(Delimiter::Bracket, TokenStream::from(stream));
trees.push(crate::Group::_new_stable(group).into());
for tt in &mut trees {
tt.set_span(span);
Expand Down

0 comments on commit 6d9a579

Please sign in to comment.