Diesel: Codegen errors when `proc_macro` feature enabled

Created on 2 Oct 2017  路  1Comment  路  Source: diesel-rs/diesel

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 https://github.com/rust-lang/rust/issues/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.

>All comments

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

Was this page helpful?
0 / 5 - 0 ratings