Rfcs: include! macro fails if included file has top-level inner attributes

Created on 27 Jan 2015  路  5Comments  路  Source: rust-lang/rfcs

Issue by dwrensha
_Sunday Nov 09, 2014 at 14:25 GMT_

_For earlier discussion, see https://github.com/rust-lang/rust/issues/18810_

_This issue was labelled with: in the Rust repository_


// test.rs

pub mod included {
    include!("test_included.rs")
}

fn main() {}
// test_included.rs

#![allow(dead_code)]

pub fn foo() {}
$ rustc test.rs
test_included.rs:3:3: 3:4 error: an inner attribute is not permitted in this context
test_included.rs:3 #![allow(dead_code)]
                     ^
error: aborting due to previous error

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.

T-lang

Most helpful comment

Future searchers: I stumbled on this issue as I created a generated module in build.rs and rust-lang/rust#18810 contained a work around that helped me.

Future searchers who happen to be rust newbies might be interested to know what you mean by "a work around"
I read the ticket, nothing jumped out at me, and everything I tried failed to yield any result.

I am following this guide for bindgen:
https://rust-lang.github.io/rust-bindgen/tutorial-4.html
and getting this:

error: an inner attribute is not permitted in this context
|
6 | #![allow(non_snake_case)];
| ^^^^^^^^^^^^^^^^^^^^^^^^^

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.

All 5 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 build.rs and https://github.com/rust-lang/rust/issues/18810 contained a work around that helped me.

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: I stumbled on this issue as I created a generated module in build.rs and rust-lang/rust#18810 contained a work around that helped me.

Future searchers who happen to be rust newbies might be interested to know what you mean by "a work around"
I read the ticket, nothing jumped out at me, and everything I tried failed to yield any result.

I am following this guide for bindgen:
https://rust-lang.github.io/rust-bindgen/tutorial-4.html
and getting this:

error: an inner attribute is not permitted in this context
|
6 | #![allow(non_snake_case)];
| ^^^^^^^^^^^^^^^^^^^^^^^^^

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3442853561 picture 3442853561  路  4Comments

onelson picture onelson  路  3Comments

Diggsey picture Diggsey  路  3Comments

rudolfschmidt picture rudolfschmidt  路  3Comments

steveklabnik picture steveklabnik  路  4Comments