Skip to content

Commit

Permalink
Merge pull request #1113 from dtolnay/parsequotespanned
Browse files Browse the repository at this point in the history
Add parse_quote_spanned macro = parse_quote + quote_spanned
  • Loading branch information
dtolnay authored Dec 26, 2021
2 parents c39aa78 + ce69299 commit 31c0ba6
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/parse_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,38 @@ macro_rules! parse_quote {
};
}

/// This macro is [`parse_quote!`] + [`quote_spanned!`][quote::quote_spanned].
///
/// Please refer to each of their documentation.
///
/// # Example
///
/// ```
/// use quote::{quote, quote_spanned};
/// use syn::spanned::Spanned;
/// use syn::{parse_quote_spanned, ReturnType, Signature};
///
/// // Changes `fn()` to `fn() -> Pin<Box<dyn Future<Output = ()>>>`,
/// // and `fn() -> T` to `fn() -> Pin<Box<dyn Future<Output = T>>>`,
/// // without introducing any call_site() spans.
/// fn make_ret_pinned_future(sig: &mut Signature) {
/// let ret = match &sig.output {
/// ReturnType::Default => quote_spanned!(sig.paren_token.span=> ()),
/// ReturnType::Type(_, ret) => quote!(#ret),
/// };
/// sig.output = parse_quote_spanned! {ret.span()=>
/// -> ::std::pin::Pin<::std::boxed::Box<dyn ::std::future::Future<Output = #ret>>>
/// };
/// }
/// ```
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "parsing", feature = "printing"))))]
#[macro_export]
macro_rules! parse_quote_spanned {
($span:expr=> $($tt:tt)*) => {
$crate::parse_quote::parse($crate::__private::quote::quote_spanned!($span=> $($tt)*))
};
}

////////////////////////////////////////////////////////////////////////////////
// Can parse any type that implements Parse.

Expand Down

0 comments on commit 31c0ba6

Please sign in to comment.