Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
cynecx committed Oct 15, 2021
1 parent 2176c22 commit b8a5ab6
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn instrument_speculative(
args: InstrumentArgs,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let input = syn::parse_macro_input!(item as MaybeItemFn<TokenStream>);
let input = syn::parse_macro_input!(item as MaybeItemFn);
let instrumented_function_name = input.sig.ident.to_string();
gen_function(
input.as_ref(),
Expand Down Expand Up @@ -652,24 +652,15 @@ fn gen_block<B: ToTokens>(
/// This is a more flexible/imprecise `ItemFn` type,
/// which's block may be anything that implements `ToTokens`.
#[derive(Debug, Clone)]
struct MaybeItemFn<B: ToTokens> {
struct MaybeItemFn {
attrs: Vec<Attribute>,
vis: Visibility,
sig: Signature,
block: B,
block: TokenStream,
}

impl<B: ToTokens> MaybeItemFn<B> {
fn new(attrs: Vec<Attribute>, vis: Visibility, sig: Signature, block: B) -> Self {
Self {
attrs,
vis,
sig,
block,
}
}

fn as_ref(&self) -> MaybeItemFnRef<'_, B> {
impl MaybeItemFn {
fn as_ref(&self) -> MaybeItemFnRef<'_, TokenStream> {
MaybeItemFnRef {
attrs: &self.attrs,
vis: &self.vis,
Expand All @@ -680,13 +671,18 @@ impl<B: ToTokens> MaybeItemFn<B> {
}

/// This parses a TokenStream as ItemFn/MaybeItemFn but skips the body.
impl Parse for MaybeItemFn<TokenStream> {
impl Parse for MaybeItemFn {
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
let attrs = input.call(syn::Attribute::parse_outer)?;
let vis: Visibility = input.parse()?;
let sig: Signature = input.parse()?;
let block: TokenStream = input.parse()?;
Ok(Self::new(attrs, vis, sig, block))
Ok(Self {
attrs,
vis,
sig,
block,
})
}
}

Expand Down

0 comments on commit b8a5ab6

Please sign in to comment.