Add parse_quote! macro
diff --git a/examples/heapsize2/heapsize_derive/src/lib.rs b/examples/heapsize2/heapsize_derive/src/lib.rs
index 3389b61..fd5e448 100644
--- a/examples/heapsize2/heapsize_derive/src/lib.rs
+++ b/examples/heapsize2/heapsize_derive/src/lib.rs
@@ -1,4 +1,6 @@
extern crate proc_macro;
+
+#[macro_use]
extern crate syn;
#[macro_use]
@@ -49,8 +51,7 @@
fn add_trait_bounds(mut generics: Generics) -> Generics {
for param in &mut generics.params {
if let GenericParam::Type(ref mut type_param) = *param {
- let bound = syn::parse(quote!(HeapSize).into()).unwrap();
- type_param.bounds.push(bound);
+ type_param.bounds.push(parse_quote!(HeapSize));
}
}
generics
diff --git a/src/lib.rs b/src/lib.rs
index ce9a830..292cbfb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -296,6 +296,17 @@
Ok(file)
}
+#[cfg(all(feature = "parsing", feature = "printing"))]
+#[macro_export]
+macro_rules! parse_quote {
+ ($($tt:tt)*) => {
+ ::std::result::Result::unwrap(
+ $crate::parse(
+ ::std::convert::Into::into(
+ quote!($($tt)*))))
+ };
+}
+
#[cfg(feature = "printing")]
struct TokensOrDefault<'a, T: 'a>(&'a Option<T>);