Skip to content

No attributes are available #108

@iddm

Description

@iddm

I have made a procedural macro which implements a trait with some functions for a enums. This the whole code:

#[proc_macro_derive(StateMachine, attributes(state_transitions))]
pub fn fxsm(input: TokenStream) -> TokenStream {
    // Construct a string representation of the type definition
    let s = input.to_string();

    // Parse the string representation
    let ast = syn::parse_derive_input(&s).unwrap();

    // Build the impl
    let gen = impl_fsm(&ast);

    // Return the generated impl
    gen.parse().unwrap()
}

fn impl_fsm(ast: &syn::DeriveInput) -> Tokens {
    if let syn::Body::Enum(ref variants) = ast.body {
        if let Some(ref a) = ast.attrs.iter().find(|a| a.name() == "derive") {
            if let syn::MetaItem::List(_, ref nested) = a.value {
                if derives(nested, "Copy") {
                    return gen_for_copyable(&ast.ident,
                                            &variants,
                                            &ast.generics);
                } else if derives(nested, "Clone") {
                    return gen_for_clonable(&ast.ident,
                                            &variants,
                                            &ast.generics);
                } else {
                    panic!("Unable to produce State Machine code on a enum which does not drive Copy nor Clone traits.");
                }
            } else {
                panic!("Unable to produce State Machine code on a enum which does not drive Copy nor Clone traits.");
            }
        } else {
            panic!("How were you able to call me without derive!?!?");
        }
    } else {
        panic!("State Machine must be derived on a enum.");
    }
}

This code worked perfectly like 2 weeks ago but now I have tried to compile it and it can't find any attribute on this struct! As you can see, I try to see what derives does the enum have but now this list is empty! What happened?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions