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

[Rust] error: an inner attribute is not permitted in this context - #4968 regression #6261

Closed
rib opened this issue Nov 14, 2020 · 5 comments · Fixed by #6410
Closed

[Rust] error: an inner attribute is not permitted in this context - #4968 regression #6261

rib opened this issue Nov 14, 2020 · 5 comments · Fixed by #6410
Assignees

Comments

@rib
Copy link

rib commented Nov 14, 2020

Commit 9fa1d27 re-introduces #![allow(unused_imports, dead_code)] into generated rust code which causes the same error that was once resolved by #4968 and #5013

The same as @csmoe we include generated rust code like:

mod foo {
    include!(concat!(env!("OUT_DIR"), "/protocol_generated.rs"));
}

Considering that our build.rs script generates the code in Cargo's given build directory as opposed to generating and storing our code in the src/ directory.

This is the error I see:

error: an inner attribute is not permitted in this context
 --> /home/rib/src/realfit-rest-apis/target/debug/build/workoutdb-b7c2283dc82717f7/out/flatbuffers/RFWorkouts_generated.rs:4:1
  |
4 | #![allow(unused_imports, dead_code)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.

We can't follow the approach used by the tutorials of doing:

#[allow(dead_code, unused_imports)]
#[path = "./monster_generated.rs"]
mod monster_generated;

since it's not possible to concatenate the path to OUT_DIR within #[path = ]

@CasperN
Copy link
Collaborator

CasperN commented Nov 16, 2020

This just entails removing the allow clause at the root of the file right? This means schema-writers who don't use namespaces have to write their own allows, which isn't too bad.

You might want to comment on: #5589 (comment)

  • I'm trying to figure out how to better manage C-style namespaces in Rust.

@rib
Copy link
Author

rib commented Nov 17, 2020

Right, I think it's just a question of removing any #![] directives from the top of the generated code. For now I ended up reverting to a402b3a as a lazy workaround.

@CasperN
Copy link
Collaborator

CasperN commented Nov 17, 2020

Btw would your example work if you created a file, foo.rs with contents

include!(concat!(env!("OUT_DIR"), "/protocol_generated.rs"));

?

@jcrevier
Copy link

jcrevier commented Dec 15, 2020

Btw would your example work if you created a file, foo.rs with contents

include!(concat!(env!("OUT_DIR"), "/protocol_generated.rs"));

?

I'm running into this issue as well. As far as I can tell it doesn't matter if the include! invocation is inside a module in a file, or if the file itself serves as the module.

@nerdrew
Copy link

nerdrew commented Jan 13, 2021

Thoughts on adding a flag to flatc to add the allow statement in the generated rust?

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

Successfully merging a pull request may close this issue.

4 participants