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

error: an inner attribute is not permitted in this context #138

Closed
9876691 opened this issue Aug 2, 2022 · 7 comments · Fixed by #144
Closed

error: an inner attribute is not permitted in this context #138

9876691 opened this issue Aug 2, 2022 · 7 comments · Fixed by #144
Assignees
Labels
bug Something isn't working

Comments

@9876691
Copy link

9876691 commented Aug 2, 2022

I'm getting the following error from the generated code. If I edit cornucopia.rs directly and make the changes the compiler suggests it works again.

error: an inner attribute is not permitted in this context
  --> /workspace/target/debug/build/app-62a31f47f074433e/out/cornucopia.rs:5:5
   |
5  |       #![allow(dead_code)]
   |       ^^^^^^^^^^^^^^^^^^^^
6  | /     pub mod types { pub mod public { #[derive( Debug, postgres_types::ToSql, postgres_types::FromSql, Clone, Copy, PartialEq, Eq)]
7  | |                         #[postgres(name = "audit_action")]
8  | |                         pub enum AuditAction { AddMember,DeleteMember,AddSecret,DeleteSecret,AccessSecrets,NewServiceAccount,DeleteServic...
9  | | #[derive( Debug, postgres_types::ToSql, postgres_types::FromSql, Clone, Copy, PartialEq, Eq)]
...  |
16 | |                         #[postgres(name = "permission")]
17 | |                         pub enum Permission { ManageTeam } } }pub mod queries { pub mod audit { use futures::{{StreamExt, TryStreamExt}};...
   | |______________________________________________________________- the inner attribute doesn't annotate this module
   |
   = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the module, change the attribute from inner to outer style
   |
5  -     #![allow(dead_code)]
5  +     #[allow(dead_code)]
@LouisGariepy
Copy link
Member

LouisGariepy commented Aug 2, 2022

This is a consequence of using the include! macro (as I suspect you are doing, please let me know if I'm wrong), and not something specific to Cornucopia. See these issues: rust-lang/rust#66920, rust-lang/rfcs#752.

Until this Rust limitation is solved, one workaround is to use a path annotation instead of include!:

#[path = "path/to/the/generated/cornucopia/module"]
mod cornucopia;

Please let me know if this works for you. If not, I have some other ideas up my sleeve, but honestly I'd prefer to keep the attributes as is if possible.

Cheers! Thanks for your interest in Cornucopia.


FYI, changing the attributes from inner (#![...]) to outer (#[...]) will not work as intended since it will only apply these attributes to the next module, not the whole parent file. However, you can manually remove these annotations if you are intent on it, as they are simply lint-related attributes (clippy and rustc will produce warnings then, though).

@9876691
Copy link
Author

9876691 commented Aug 3, 2022

I think the below doesn't work with build.rs as the path changes based on the OUT_DIR env var which cargo supplies.

#[path = "path/to/the/generated/cornucopia/module"]
mod cornucopia;

So I wrote some code to do a search and replace on the #![...] and now it's working.

@9876691 9876691 closed this as completed Aug 3, 2022
@LouisGariepy
Copy link
Member

@ianpurton I can definitely solve this on our side, so please feel free to reopen this issue at any time if you feel like its troublesome for you. If there's a choice to make between codegen complexity and user experience, I'll always pick user experience! I just wanted to try the path method first.

@jgreenbaum
Copy link

I think it would be great if you could fix this.

@9876691 9876691 reopened this Aug 27, 2022
@LouisGariepy
Copy link
Member

I'll fix this as soon as possible 😃 Should be relatively quick.

@LouisGariepy
Copy link
Member

LouisGariepy commented Aug 28, 2022

@ianpurton @jgreenbaum

I just published a minor release that should fix this issue! Please let me know if there's still something amiss.

Thanks for making Cornucopia better!

@9876691
Copy link
Author

9876691 commented Sep 3, 2022

@LouisGariepy Thanks. I've tried it and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants