From 4e74c181a4f16adf72ff0f9adbf6faca8fe5d1df Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Thu, 14 Jul 2016 08:55:48 +0000 Subject: [PATCH 1/2] Make `ext::base::expr_to_string` work correctly with `include!` macro invocations --- src/libsyntax/ext/base.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 92670cd9def90..70d924cf46d06 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -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, 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 { From 11f24a93c79a5ff5ecd2c238c603bdab30926bb3 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Thu, 14 Jul 2016 08:59:25 +0000 Subject: [PATCH 2/2] Add regression test --- src/test/compile-fail/macro-expanded-include/foo/mod.rs | 4 ++++ src/test/compile-fail/macro-expanded-include/test.rs | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/compile-fail/macro-expanded-include/foo/mod.rs b/src/test/compile-fail/macro-expanded-include/foo/mod.rs index 57b7b72a1d435..888bdf5179a23 100644 --- a/src/test/compile-fail/macro-expanded-include/foo/mod.rs +++ b/src/test/compile-fail/macro-expanded-include/foo/mod.rs @@ -13,3 +13,7 @@ macro_rules! m { () => { include!("file.txt"); } } + +macro_rules! n { + () => { unsafe { asm!(include_str!("file.txt")); } } +} diff --git a/src/test/compile-fail/macro-expanded-include/test.rs b/src/test/compile-fail/macro-expanded-include/test.rs index 7ab9dd19b1b70..e1e85ddb2c1b1 100644 --- a/src/test/compile-fail/macro-expanded-include/test.rs +++ b/src/test/compile-fail/macro-expanded-include/test.rs @@ -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