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

Codegen errors when `proc_macro` feature enabled #1232

Closed
kardeiz opened this Issue Oct 2, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@kardeiz
Contributor

kardeiz commented Oct 2, 2017

If you have the proc_macro feature enabled and use Diesel's codegen derives, you will (usually) get compilation errors like:

cannot find attribute macro 'table_name' in this scope. 

I realized that I wasn't having the same issue with serde's derive/attributes, and discovered that it is because, when proc_macro is enabled, it only allows the set of whitelisted attributes for the first derived trait. So if you use only #[derive(Queryable) (or any one trait), you are fine. If you #[derive(Queryable, Identifiable) you will get an error.

I think this has to be a bug in proc_macro. This can be worked around in Diesel by putting all the possible attributes in each attribute set, for example in diesel_codegen like:

#[proc_macro_derive(Queryable, attributes(table_name, column_name, primary_key, etc))]

However, if you need custom derives on a struct from both Diesel and, say, serde, you would be in trouble; only the top level attributes from one library or the other could be applied.

See rust-lang/rust#44925 for some more details. This is not a bug in Diesel, but I am putting it here for discussion or in case anyone runs into the same issue and needs a quick fix.

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 6, 2017

As mentioned, this is not a bug in Diesel. Closing as there's nothing actionable for us to do.

@sgrif sgrif closed this Oct 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment