-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
include! macro fails if included file has top-level inner attributes #752
Comments
On the latest nightly, I still get the same error (after inserting a semicolon to account for the new macro syntax). |
Future searchers: I stumbled on this issue as I created a generated module in |
Due to rust-lang/rust#18810 (rust-lang/rfcs#752) it is not possible to have an inner attribute in a file that gets used with `include!`. Specifying the attribute on each parser module is less precise and more duplication but it will at least work for that case. If a user wants to apply the rustfmt on the whole module they can still add an outer attribute manually as well.
After running into this issue still, I implemented a hacky workaround for this issue with the upcoming procedural macros feature: https://github.com/peterhuene/azure-functions-rs/blob/master/azure-functions-shared-codegen/src/lib.rs |
Future searchers who happen to be rust newbies might be interested to know what you mean by "a work around" I am following this guide for bindgen: error: an inner attribute is not permitted in this context It is hard to google for the difference between #![allow... and #[allow... and although the error explains what the difference between an inner and outer attribute is, it doesn't explain help me understand why the tutorial doesn't work as explained. |
It happens yet, are there news about if there will be a solution? |
I haven't tried it myself, but I think that, starting in rustc 1.54, something like this now works:
See https://blog.rust-lang.org/2021/07/29/Rust-1.54.0.html#attributes-can-invoke-function-like-macros |
Unfortunately this doesn't work
|
It's also worth noting that this also happens if you |
It looks like the issue is still here... I cannot include protobuf generated code, getting a bunch of errors:
|
@DimanNe as I just came across the same problem, and I saw your comment in the rust-protobuf repo as well, the way out of this is: generate with
I guess the suggested workarounds above are a similar suggestions in nature? unfortunately, this was the only way for me out of this. |
Issue by dwrensha
Sunday Nov 09, 2014 at 14:25 GMT
For earlier discussion, see rust-lang/rust#18810
This issue was labelled with: in the Rust repository
I at first thought that the problem was due to the implicit insert of the prelude in the
included
module. However, adding a#[no_implicit_prelude]
attribute does not help.The text was updated successfully, but these errors were encountered: