Skip to content

Commit

Permalink
Remove Expr newtype struct
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 29, 2023
1 parent bb41599 commit ac7b06c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
12 changes: 2 additions & 10 deletions src/expr.rs
Expand Up @@ -3,9 +3,7 @@ use proc_macro::token_stream::IntoIter as TokenIter;
use proc_macro::{Spacing, Span, TokenStream, TokenTree};
use std::iter;

pub struct Expr(TokenStream);

pub fn parse(input: &mut TokenIter) -> Result<Expr> {
pub fn parse(input: &mut TokenIter) -> Result<TokenStream> {
#[derive(PartialEq)]
enum Lookbehind {
JointColon,
Expand All @@ -25,7 +23,7 @@ pub fn parse(input: &mut TokenIter) -> Result<Expr> {
let spacing = punct.spacing();
expr.extend(iter::once(TokenTree::Punct(punct)));
lookbehind = match ch {
',' if angle_bracket_depth == 0 => return Ok(Expr(expr)),
',' if angle_bracket_depth == 0 => return Ok(expr),
':' if lookbehind == Lookbehind::JointColon => Lookbehind::DoubleColon,
':' if spacing == Spacing::Joint => Lookbehind::JointColon,
'<' if lookbehind == Lookbehind::DoubleColon => {
Expand All @@ -50,9 +48,3 @@ pub fn parse(input: &mut TokenIter) -> Result<Expr> {
}
}
}

impl Expr {
pub fn into_tokens(self) -> TokenStream {
self.0
}
}
3 changes: 1 addition & 2 deletions src/lib.rs
Expand Up @@ -121,7 +121,6 @@ mod expr;
mod unindent;

use crate::error::{Error, Result};
use crate::expr::Expr;
use crate::unindent::unindent;
use proc_macro::token_stream::IntoIter as TokenIter;
use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
Expand Down Expand Up @@ -320,7 +319,7 @@ fn try_expand(input: TokenStream, mode: Macro) -> Result<TokenStream> {
TokenTree::Group(Group::new(
Delimiter::Brace,
prefix
.map_or_else(TokenStream::new, Expr::into_tokens)
.unwrap_or_else(TokenStream::new)
.into_iter()
.chain(iter::once(TokenTree::Literal(unindented_lit)))
.chain(input)
Expand Down

0 comments on commit ac7b06c

Please sign in to comment.