use core::borrow::BorrowMut;
use proc_macro::TokenStream;
use quote::quote;
use syn::{fold::Fold, parse_macro_input, FnArg, ItemFn, Type};
struct Args {}
impl Fold for Args {
fn fold_fn_arg(&mut self, mut i: syn::FnArg) -> syn::FnArg {
match i.borrow_mut() {
FnArg::Typed(x) => {
match x.ty.as_mut() {
Type::Reference(r) => {
r.lifetime = None;
}
_ => {
}
}
}
_ => {
}
}
syn::fold::fold_fn_arg(self, i)
}
}
#[proc_macro_attribute]
pub fn remove_lifetimes_from_fn_args(
_args: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as ItemFn);
let mut args = Args {};
let output = args.fold_item_fn(input);
TokenStream::from(quote!(#output))
}