Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No attributes are available #108

Closed
iddm opened this issue Mar 16, 2017 · 2 comments
Closed

No attributes are available #108

iddm opened this issue Mar 16, 2017 · 2 comments

Comments

@iddm
Copy link

iddm commented Mar 16, 2017

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?

@dtolnay
Copy link
Owner

dtolnay commented Mar 16, 2017

This changed in rust-lang/rust#39572. Open a Rust issue explaining your use case and asking for rust-lang/rust#39572 (comment).

@iddm
Copy link
Author

iddm commented Mar 16, 2017

@dtolnay thanks for pointing me there.

@dtolnay dtolnay closed this as completed Mar 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants