Skip to content

Commit

Permalink
Remove use of From when a newtype variant constructor suffices
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 21, 2024
1 parent 13092b8 commit a720d9f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@ impl From<fallback::TokenStream> for TokenStream {
// Assumes inside_proc_macro().
fn into_compiler_token(token: TokenTree) -> proc_macro::TokenTree {
match token {
TokenTree::Group(tt) => proc_macro::TokenTree::from(tt.inner.unwrap_nightly()),
TokenTree::Group(tt) => proc_macro::TokenTree::Group(tt.inner.unwrap_nightly()),
TokenTree::Punct(tt) => {
let spacing = match tt.spacing() {
Spacing::Joint => proc_macro::Spacing::Joint,
Spacing::Alone => proc_macro::Spacing::Alone,
};
let mut punct = proc_macro::Punct::new(tt.as_char(), spacing);
punct.set_span(tt.span().inner.unwrap_nightly());
proc_macro::TokenTree::from(punct)
proc_macro::TokenTree::Punct(punct)
}
TokenTree::Ident(tt) => proc_macro::TokenTree::from(tt.inner.unwrap_nightly()),
TokenTree::Literal(tt) => proc_macro::TokenTree::from(tt.inner.unwrap_nightly()),
TokenTree::Ident(tt) => proc_macro::TokenTree::Ident(tt.inner.unwrap_nightly()),
TokenTree::Literal(tt) => proc_macro::TokenTree::Literal(tt.inner.unwrap_nightly()),
}
}

Expand Down Expand Up @@ -339,7 +339,7 @@ impl Iterator for TokenTreeIter {
};
Some(match token {
proc_macro::TokenTree::Group(tt) => {
TokenTree::from(crate::Group::_new(Group::Compiler(tt)))
TokenTree::Group(crate::Group::_new(Group::Compiler(tt)))
}
proc_macro::TokenTree::Punct(tt) => {
let spacing = match tt.spacing() {
Expand All @@ -348,13 +348,13 @@ impl Iterator for TokenTreeIter {
};
let mut o = Punct::new(tt.as_char(), spacing);
o.set_span(crate::Span::_new(Span::Compiler(tt.span())));
TokenTree::from(o)
TokenTree::Punct(o)
}
proc_macro::TokenTree::Ident(s) => {
TokenTree::from(crate::Ident::_new(Ident::Compiler(s)))
TokenTree::Ident(crate::Ident::_new(Ident::Compiler(s)))
}
proc_macro::TokenTree::Literal(l) => {
TokenTree::from(crate::Literal::_new(Literal::Compiler(l)))
TokenTree::Literal(crate::Literal::_new(Literal::Compiler(l)))
}
})
}
Expand Down

0 comments on commit a720d9f

Please sign in to comment.