runtime, macros: unify NaN-boxed value API under ValueVariant trait
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
extern crate proc_macro;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn unelide_lifetimes(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
use quote::ToTokens;
|
||||
use syn::parse::{Parse, ParseStream};
|
||||
use syn::visit_mut::VisitMut;
|
||||
|
||||
struct Input {
|
||||
lt: syn::Lifetime,
|
||||
ty: syn::Type,
|
||||
}
|
||||
|
||||
impl Parse for Input {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
let lt: syn::Lifetime = input.parse()?;
|
||||
let _: syn::Token!(;) = input.parse()?;
|
||||
let ty: syn::Type = input.parse()?;
|
||||
Ok(Self { lt, ty })
|
||||
}
|
||||
}
|
||||
|
||||
struct UnelideLifetimes(syn::Lifetime);
|
||||
|
||||
impl VisitMut for UnelideLifetimes {
|
||||
fn visit_lifetime_mut(&mut self, i: &mut syn::Lifetime) {
|
||||
if i.ident == "_" {
|
||||
*i = self.0.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut input = syn::parse_macro_input!(input as Input);
|
||||
UnelideLifetimes(input.lt).visit_type_mut(&mut input.ty);
|
||||
input.ty.to_token_stream().into()
|
||||
}
|
||||
Reference in New Issue
Block a user