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

Fix include!()s inside asm!() invocations #34816

Merged
merged 2 commits into from
Jul 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,12 @@ impl<'a> ExtCtxt<'a> {
/// compilation on error, merely emits a non-fatal error and returns None.
pub fn expr_to_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &str)
-> Option<(InternedString, ast::StrStyle)> {
// Update `expr.span`'s expn_id now in case expr is an `include!` macro invocation.
let expr = expr.map(|mut expr| {
expr.span.expn_id = cx.backtrace;
expr
});

// we want to be able to handle e.g. concat("foo", "bar")
let expr = cx.expander().fold_expr(expr);
match expr.node {
Expand Down
4 changes: 4 additions & 0 deletions src/test/compile-fail/macro-expanded-include/foo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
macro_rules! m {
() => { include!("file.txt"); }
}

macro_rules! n {
() => { unsafe { asm!(include_str!("file.txt")); } }
}
4 changes: 3 additions & 1 deletion src/test/compile-fail/macro-expanded-include/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(rustc_attrs)]
#![feature(asm, rustc_attrs)]
#![allow(unused)]

#[macro_use]
mod foo;

m!();
fn f() { n!(); }

#[rustc_error]
fn main() {} //~ ERROR compilation successful