Skip to content

Instantly share code, notes, and snippets.

@danielhenrymantilla
Forked from jmg-duarte/parse_quote_dbg.rs
Created September 17, 2021 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielhenrymantilla/96b1d5b0db83ad7440a306763d2d97d4 to your computer and use it in GitHub Desktop.
Save danielhenrymantilla/96b1d5b0db83ad7440a306763d2d97d4 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