1fad3a1d3Sopenharmony_ci#![allow(unused_macros, unused_macro_rules)] 2fad3a1d3Sopenharmony_ci 3fad3a1d3Sopenharmony_ci#[path = "../debug/mod.rs"] 4fad3a1d3Sopenharmony_cipub mod debug; 5fad3a1d3Sopenharmony_ci 6fad3a1d3Sopenharmony_ciuse std::str::FromStr; 7fad3a1d3Sopenharmony_ciuse syn::parse::Result; 8fad3a1d3Sopenharmony_ci 9fad3a1d3Sopenharmony_cimacro_rules! errorf { 10fad3a1d3Sopenharmony_ci ($($tt:tt)*) => {{ 11fad3a1d3Sopenharmony_ci use ::std::io::Write; 12fad3a1d3Sopenharmony_ci let stderr = ::std::io::stderr(); 13fad3a1d3Sopenharmony_ci write!(stderr.lock(), $($tt)*).unwrap(); 14fad3a1d3Sopenharmony_ci }}; 15fad3a1d3Sopenharmony_ci} 16fad3a1d3Sopenharmony_ci 17fad3a1d3Sopenharmony_cimacro_rules! punctuated { 18fad3a1d3Sopenharmony_ci ($($e:expr,)+) => {{ 19fad3a1d3Sopenharmony_ci let mut seq = ::syn::punctuated::Punctuated::new(); 20fad3a1d3Sopenharmony_ci $( 21fad3a1d3Sopenharmony_ci seq.push($e); 22fad3a1d3Sopenharmony_ci )+ 23fad3a1d3Sopenharmony_ci seq 24fad3a1d3Sopenharmony_ci }}; 25fad3a1d3Sopenharmony_ci 26fad3a1d3Sopenharmony_ci ($($e:expr),+) => { 27fad3a1d3Sopenharmony_ci punctuated!($($e,)+) 28fad3a1d3Sopenharmony_ci }; 29fad3a1d3Sopenharmony_ci} 30fad3a1d3Sopenharmony_ci 31fad3a1d3Sopenharmony_cimacro_rules! snapshot { 32fad3a1d3Sopenharmony_ci ($($args:tt)*) => { 33fad3a1d3Sopenharmony_ci snapshot_impl!(() $($args)*) 34fad3a1d3Sopenharmony_ci }; 35fad3a1d3Sopenharmony_ci} 36fad3a1d3Sopenharmony_ci 37fad3a1d3Sopenharmony_cimacro_rules! snapshot_impl { 38fad3a1d3Sopenharmony_ci (($expr:ident) as $t:ty, @$snapshot:literal) => { 39fad3a1d3Sopenharmony_ci let tokens = crate::macros::TryIntoTokens::try_into_tokens($expr).unwrap(); 40fad3a1d3Sopenharmony_ci let $expr: $t = syn::parse_quote!(#tokens); 41fad3a1d3Sopenharmony_ci let debug = crate::macros::debug::Lite(&$expr); 42fad3a1d3Sopenharmony_ci if !cfg!(miri) { 43fad3a1d3Sopenharmony_ci #[allow(clippy::needless_raw_string_hashes)] // https://github.com/mitsuhiko/insta/issues/389 44fad3a1d3Sopenharmony_ci { 45fad3a1d3Sopenharmony_ci insta::assert_debug_snapshot!(debug, @$snapshot); 46fad3a1d3Sopenharmony_ci } 47fad3a1d3Sopenharmony_ci } 48fad3a1d3Sopenharmony_ci }; 49fad3a1d3Sopenharmony_ci (($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{ 50fad3a1d3Sopenharmony_ci let tokens = crate::macros::TryIntoTokens::try_into_tokens($($expr)*).unwrap(); 51fad3a1d3Sopenharmony_ci let syntax_tree: $t = syn::parse_quote!(#tokens); 52fad3a1d3Sopenharmony_ci let debug = crate::macros::debug::Lite(&syntax_tree); 53fad3a1d3Sopenharmony_ci if !cfg!(miri) { 54fad3a1d3Sopenharmony_ci #[allow(clippy::needless_raw_string_hashes)] 55fad3a1d3Sopenharmony_ci { 56fad3a1d3Sopenharmony_ci insta::assert_debug_snapshot!(debug, @$snapshot); 57fad3a1d3Sopenharmony_ci } 58fad3a1d3Sopenharmony_ci } 59fad3a1d3Sopenharmony_ci syntax_tree 60fad3a1d3Sopenharmony_ci }}; 61fad3a1d3Sopenharmony_ci (($($expr:tt)*) , @$snapshot:literal) => {{ 62fad3a1d3Sopenharmony_ci let syntax_tree = $($expr)*; 63fad3a1d3Sopenharmony_ci let debug = crate::macros::debug::Lite(&syntax_tree); 64fad3a1d3Sopenharmony_ci if !cfg!(miri) { 65fad3a1d3Sopenharmony_ci #[allow(clippy::needless_raw_string_hashes)] 66fad3a1d3Sopenharmony_ci { 67fad3a1d3Sopenharmony_ci insta::assert_debug_snapshot!(debug, @$snapshot); 68fad3a1d3Sopenharmony_ci } 69fad3a1d3Sopenharmony_ci } 70fad3a1d3Sopenharmony_ci syntax_tree 71fad3a1d3Sopenharmony_ci }}; 72fad3a1d3Sopenharmony_ci (($($expr:tt)*) $next:tt $($rest:tt)*) => { 73fad3a1d3Sopenharmony_ci snapshot_impl!(($($expr)* $next) $($rest)*) 74fad3a1d3Sopenharmony_ci }; 75fad3a1d3Sopenharmony_ci} 76fad3a1d3Sopenharmony_ci 77fad3a1d3Sopenharmony_cipub trait TryIntoTokens { 78fad3a1d3Sopenharmony_ci fn try_into_tokens(self) -> Result<proc_macro2::TokenStream>; 79fad3a1d3Sopenharmony_ci} 80fad3a1d3Sopenharmony_ci 81fad3a1d3Sopenharmony_ciimpl<'a> TryIntoTokens for &'a str { 82fad3a1d3Sopenharmony_ci fn try_into_tokens(self) -> Result<proc_macro2::TokenStream> { 83fad3a1d3Sopenharmony_ci let tokens = proc_macro2::TokenStream::from_str(self)?; 84fad3a1d3Sopenharmony_ci Ok(tokens) 85fad3a1d3Sopenharmony_ci } 86fad3a1d3Sopenharmony_ci} 87fad3a1d3Sopenharmony_ci 88fad3a1d3Sopenharmony_ciimpl TryIntoTokens for proc_macro2::TokenStream { 89fad3a1d3Sopenharmony_ci fn try_into_tokens(self) -> Result<proc_macro2::TokenStream> { 90fad3a1d3Sopenharmony_ci Ok(self) 91fad3a1d3Sopenharmony_ci } 92fad3a1d3Sopenharmony_ci} 93