From bce0e5f0abae6a945e664343b6c92d2c5b37190e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 19 Jan 2023 20:50:03 -0800 Subject: [PATCH] Consistently use Self in the return of From impls --- src/fallback.rs | 6 +++--- src/lib.rs | 12 ++++++------ src/wrapper.rs | 18 +++++++++--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/fallback.rs b/src/fallback.rs index 5a4c350d..587395d6 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -234,7 +234,7 @@ impl Debug for TokenStream { #[cfg(use_proc_macro)] impl From for TokenStream { - fn from(inner: proc_macro::TokenStream) -> TokenStream { + fn from(inner: proc_macro::TokenStream) -> Self { inner .to_string() .parse() @@ -244,7 +244,7 @@ impl From for TokenStream { #[cfg(use_proc_macro)] impl From for proc_macro::TokenStream { - fn from(inner: TokenStream) -> proc_macro::TokenStream { + fn from(inner: TokenStream) -> Self { inner .to_string() .parse() @@ -253,7 +253,7 @@ impl From for proc_macro::TokenStream { } impl From for TokenStream { - fn from(tree: TokenTree) -> TokenStream { + fn from(tree: TokenTree) -> Self { let mut stream = RcVecBuilder::new(); push_token_from_proc_macro(stream.as_mut(), tree); TokenStream { diff --git a/src/lib.rs b/src/lib.rs index 633333ba..e91eb070 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -231,14 +231,14 @@ impl FromStr for TokenStream { #[cfg(use_proc_macro)] impl From for TokenStream { - fn from(inner: proc_macro::TokenStream) -> TokenStream { + fn from(inner: proc_macro::TokenStream) -> Self { TokenStream::_new(inner.into()) } } #[cfg(use_proc_macro)] impl From for proc_macro::TokenStream { - fn from(inner: TokenStream) -> proc_macro::TokenStream { + fn from(inner: TokenStream) -> Self { inner.inner.into() } } @@ -574,25 +574,25 @@ impl TokenTree { } impl From for TokenTree { - fn from(g: Group) -> TokenTree { + fn from(g: Group) -> Self { TokenTree::Group(g) } } impl From for TokenTree { - fn from(g: Ident) -> TokenTree { + fn from(g: Ident) -> Self { TokenTree::Ident(g) } } impl From for TokenTree { - fn from(g: Punct) -> TokenTree { + fn from(g: Punct) -> Self { TokenTree::Punct(g) } } impl From for TokenTree { - fn from(g: Literal) -> TokenTree { + fn from(g: Literal) -> Self { TokenTree::Literal(g) } } diff --git a/src/wrapper.rs b/src/wrapper.rs index bc800d56..f5ec06b6 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -131,13 +131,13 @@ impl Display for TokenStream { } impl From for TokenStream { - fn from(inner: proc_macro::TokenStream) -> TokenStream { + fn from(inner: proc_macro::TokenStream) -> Self { TokenStream::Compiler(DeferredTokenStream::new(inner)) } } impl From for proc_macro::TokenStream { - fn from(inner: TokenStream) -> proc_macro::TokenStream { + fn from(inner: TokenStream) -> Self { match inner { TokenStream::Compiler(inner) => inner.into_token_stream(), TokenStream::Fallback(inner) => inner.to_string().parse().unwrap(), @@ -146,7 +146,7 @@ impl From for proc_macro::TokenStream { } impl From for TokenStream { - fn from(inner: fallback::TokenStream) -> TokenStream { + fn from(inner: fallback::TokenStream) -> Self { TokenStream::Fallback(inner) } } @@ -170,7 +170,7 @@ fn into_compiler_token(token: TokenTree) -> proc_macro::TokenTree { } impl From for TokenStream { - fn from(token: TokenTree) -> TokenStream { + fn from(token: TokenTree) -> Self { if inside_proc_macro() { TokenStream::Compiler(DeferredTokenStream::new(into_compiler_token(token).into())) } else { @@ -263,13 +263,13 @@ impl LexError { } impl From for LexError { - fn from(e: proc_macro::LexError) -> LexError { + fn from(e: proc_macro::LexError) -> Self { LexError::Compiler(e) } } impl From for LexError { - fn from(e: fallback::LexError) -> LexError { + fn from(e: fallback::LexError) -> Self { LexError::Fallback(e) } } @@ -539,13 +539,13 @@ impl Span { } impl From for crate::Span { - fn from(proc_span: proc_macro::Span) -> crate::Span { + fn from(proc_span: proc_macro::Span) -> Self { crate::Span::_new(Span::Compiler(proc_span)) } } impl From for Span { - fn from(inner: fallback::Span) -> Span { + fn from(inner: fallback::Span) -> Self { Span::Fallback(inner) } } @@ -929,7 +929,7 @@ impl Literal { } impl From for Literal { - fn from(s: fallback::Literal) -> Literal { + fn from(s: fallback::Literal) -> Self { Literal::Fallback(s) } }