Last active
May 6, 2023 19:10
-
-
Save jmg-duarte/4e2e5030d0f53f5dc9f7223c6499f9b8 to your computer and use it in GitHub Desktop.
Yandros parse_quote! debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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