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

include! macro fails if included file has top-level inner attributes #752

Open
steveklabnik opened this Issue Jan 27, 2015 · 4 comments

Comments

Projects
None yet
7 participants
@steveklabnik
Copy link
Member

steveklabnik commented Jan 27, 2015

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


// 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.

@SimonSapin

This comment has been minimized.

@dwrensha

This comment has been minimized.

Copy link

dwrensha commented Jan 27, 2015

On the latest nightly, I still get the same error (after inserting a semicolon to account for the new macro syntax).

@SirVer

This comment has been minimized.

Copy link

SirVer commented Dec 8, 2016

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.

@Centril Centril added the T-lang label Feb 23, 2018

Marwes added a commit to Marwes/lalrpop that referenced this issue Mar 17, 2018

fix: Allow lalrpop parsers to be used with include!
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.
@peterhuene

This comment has been minimized.

Copy link

peterhuene commented Jul 31, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.