Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upinclude! macro fails if included file has top-level inner attributes #18810
Comments
dwrensha
referenced this issue
Nov 9, 2014
Open
Add #[allow(dead_code)] and #[allow(non_camel_case_types)] to the generated code #15
This comment has been minimized.
This comment has been minimized.
|
I’ve written a syntax extension (below) to work around this. mod_path! foo (concat!(env!("OUT_DIR"), "/hello.rs"))Expands to:
@alexcrichton I suggest adding this to libsyntax and making it the recommended way to use generated code in Cargo. (#824) Should it go through the RFC process? #![crate_type="dylib"]
#![feature(plugin_registrar, quote)]
extern crate syntax;
extern crate rustc;
use syntax::codemap::Span;
use syntax::parse::token;
use syntax::ast::{TokenTree, Ident};
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacItems, IdentTT, get_single_str_from_tts};
use rustc::plugin::Registry;
fn expand_mod_path<'a>(cx: &'a mut ExtCtxt, sp: Span, ident: Ident, tts: Vec<TokenTree>)
-> Box<MacResult + 'a> {
let path = match get_single_str_from_tts(cx, sp, tts.as_slice(), "mod_path!") {
Some(string) => string,
None => return DummyResult::expr(sp),
};
MacItems::new(vec![quote_item!(cx,
#[path = $path]
mod $ident;
).unwrap()].into_iter())
}
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_syntax_extension(token::intern("mod_path"), IdentTT(box expand_mod_path, None));
} |
This comment has been minimized.
This comment has been minimized.
|
Something like that would definitely need to go through the RFC process, but that seems great to me! |
This comment has been minimized.
This comment has been minimized.
|
#18849 might be a better solution. |
SimonSapin
referenced this issue
Jan 22, 2015
Merged
Turn `extern crate` and `use` into first-class items. #20179
This comment has been minimized.
This comment has been minimized.
|
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#752 |
steveklabnik
closed this
Jan 27, 2015
steveklabnik
referenced this issue
Jan 27, 2015
Open
include! macro fails if included file has top-level inner attributes #752
This comment has been minimized.
This comment has been minimized.
|
I’ve published the plugin above as a |
dwrensha commentedNov 9, 2014
I at first thought that the problem was due to the implicit insert of the prelude in the
includedmodule. However, adding a#[no_implicit_prelude]attribute does not help.