From 8a3962ed4238e16b305e35a70d1b1e4fa45dc78d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 20 Nov 2024 16:11:56 -0800 Subject: [PATCH] Spell out types in FromStr conversions --- src/fallback.rs | 9 ++------- src/lib.rs | 12 +++++++----- src/wrapper.rs | 13 ++++++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/fallback.rs b/src/fallback.rs index 2d1c991..3a0e760 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -226,19 +226,14 @@ impl Debug for TokenStream { #[cfg(feature = "proc-macro")] impl From for TokenStream { fn from(inner: proc_macro::TokenStream) -> Self { - inner - .to_string() - .parse() - .expect("compiler token stream parse failed") + TokenStream::from_str(&inner.to_string()).expect("compiler token stream parse failed") } } #[cfg(feature = "proc-macro")] impl From for proc_macro::TokenStream { fn from(inner: TokenStream) -> Self { - inner - .to_string() - .parse() + proc_macro::TokenStream::from_str(&inner.to_string()) .expect("failed to parse to compiler tokens") } } diff --git a/src/lib.rs b/src/lib.rs index 29853bb..d5d8ec3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -245,7 +245,7 @@ impl FromStr for TokenStream { type Err = LexError; fn from_str(src: &str) -> Result { - let e = src.parse().map_err(|e| LexError { + let e = imp::TokenStream::from_str(src).map_err(|e| LexError { inner: e, _marker: MARKER, })?; @@ -1307,10 +1307,12 @@ impl FromStr for Literal { type Err = LexError; fn from_str(repr: &str) -> Result { - repr.parse().map(Literal::_new).map_err(|inner| LexError { - inner, - _marker: MARKER, - }) + imp::Literal::from_str(repr) + .map(Literal::_new) + .map_err(|inner| LexError { + inner, + _marker: MARKER, + }) } } diff --git a/src/wrapper.rs b/src/wrapper.rs index df3674e..a701865 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -117,14 +117,15 @@ impl FromStr for TokenStream { proc_macro_parse(src)?, ))) } else { - Ok(TokenStream::Fallback(src.parse()?)) + Ok(TokenStream::Fallback(fallback::TokenStream::from_str(src)?)) } } } // Work around https://github.com/rust-lang/rust/issues/58736. fn proc_macro_parse(src: &str) -> Result { - let result = panic::catch_unwind(|| src.parse().map_err(LexError::Compiler)); + let result = + panic::catch_unwind(|| proc_macro::TokenStream::from_str(src).map_err(LexError::Compiler)); result.unwrap_or_else(|_| Err(LexError::CompilerPanic)) } @@ -147,7 +148,9 @@ impl From for 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(), + TokenStream::Fallback(inner) => { + proc_macro::TokenStream::from_str(&inner.to_string()).unwrap() + } } } } @@ -897,7 +900,7 @@ impl Literal { #[cfg(no_literal_byte_character)] { let fallback = fallback::Literal::byte_character(byte); - fallback.repr.parse::().unwrap() + proc_macro::Literal::from_str(&fallback.repr).unwrap() } }) } else { @@ -924,7 +927,7 @@ impl Literal { #[cfg(no_literal_c_string)] { let fallback = fallback::Literal::c_string(string); - fallback.repr.parse::().unwrap() + proc_macro::Literal::from_str(&fallback.repr).unwrap() } }) } else {