diff --git a/tests/macros/mod.rs b/tests/macros/mod.rs index 3bfbe03898..ea72e2af24 100644 --- a/tests/macros/mod.rs +++ b/tests/macros/mod.rs @@ -3,7 +3,8 @@ #[path = "../debug/mod.rs"] pub mod debug; -use syn::parse::{Parse, Result}; +use std::str::FromStr; +use syn::parse::Result; macro_rules! errorf { ($($tt:tt)*) => {{ @@ -35,7 +36,8 @@ macro_rules! snapshot { macro_rules! snapshot_impl { (($expr:ident) as $t:ty, @$snapshot:literal) => { - let $expr = crate::macros::Tokens::parse::<$t>($expr).unwrap(); + let tokens = crate::macros::Tokens::tokens($expr).unwrap(); + let $expr: $t = syn::parse_quote!(#tokens); let debug = crate::macros::debug::Lite(&$expr); if !cfg!(miri) { #[allow(clippy::needless_raw_string_hashes)] // https://github.com/mitsuhiko/insta/issues/389 @@ -45,7 +47,8 @@ macro_rules! snapshot_impl { } }; (($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{ - let syntax_tree = crate::macros::Tokens::parse::<$t>($($expr)*).unwrap(); + let tokens = crate::macros::Tokens::tokens($($expr)*).unwrap(); + let syntax_tree: $t = syn::parse_quote!(#tokens); let debug = crate::macros::debug::Lite(&syntax_tree); if !cfg!(miri) { #[allow(clippy::needless_raw_string_hashes)] @@ -72,17 +75,18 @@ macro_rules! snapshot_impl { } pub trait Tokens { - fn parse(self) -> Result; + fn tokens(self) -> Result; } impl<'a> Tokens for &'a str { - fn parse(self) -> Result { - syn::parse_str(self) + fn tokens(self) -> Result { + let tokens = proc_macro2::TokenStream::from_str(self)?; + Ok(tokens) } } impl Tokens for proc_macro2::TokenStream { - fn parse(self) -> Result { - syn::parse2(self) + fn tokens(self) -> Result { + Ok(self) } }