Skip to content

Instantly share code, notes, and snippets.

@jmg-duarte
Last active May 6, 2023 19:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jmg-duarte/4e2e5030d0f53f5dc9f7223c6499f9b8 to your computer and use it in GitHub Desktop.
Save jmg-duarte/4e2e5030d0f53f5dc9f7223c6499f9b8 to your computer and use it in GitHub Desktop.
Yandros parse_quote! debug
// Credits: Yandros#4299
macro_rules! parse_quote {(
$($code:tt)*
) => ({
eprintln!("[{}:{}:{}] parse_quote! {{ {} }}", file!(), line!(), column!(), quote!( $($code)* ));
::syn::parse_quote!( $($code)* )
})}
macro_rules! parse_quote {(
$($code:tt)*
) => ((|| {
fn type_of_some<T> (_: Option<T>) -> &'static str { ::core::any::type_name::<T>() }
let target_ty = None;
if false { return target_ty.unwrap(); }
eprintln!("[{}:{}:{}] parse_quote! {{ {} }} as {}", file!(), line!(), column!(), quote!( $($code)* ), type_of_some(target_ty));
::syn::parse_quote!( $($code)* )
})())}
macro_rules! parse_quote {(
$($code:tt)*
) => (
(|| {
fn type_of_some<T> (_: Option<T>)
-> &'static str
{
::core::any::type_name::<T>()
}
let target_ty = None; if false { return target_ty.unwrap(); }
eprintln!(
"[{}:{}:{}:parse_quote!]\n - ty: `{ty}`\n - code: `{code}`",
file!(), line!(), column!(),
code = ::quote::quote!( $($code)* ),
ty = type_of_some(target_ty),
);
::syn::parse_quote!( $($code)* )
})()
)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment