Skip to content

Commit eb196dc

Browse files
authored
Auto merge of #34816 - jseyfried:fix_include_path, r=nrc
Fix `include!()`s inside `asm!()` invocations Fixes #34812, a regression caused by #33749 that was not fixed in #34450. r? @nrc
2 parents dc8212f + 11f24a9 commit eb196dc

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/libsyntax/ext/base.rs

+6
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,12 @@ impl<'a> ExtCtxt<'a> {
816816
/// compilation on error, merely emits a non-fatal error and returns None.
817817
pub fn expr_to_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &str)
818818
-> Option<(InternedString, ast::StrStyle)> {
819+
// Update `expr.span`'s expn_id now in case expr is an `include!` macro invocation.
820+
let expr = expr.map(|mut expr| {
821+
expr.span.expn_id = cx.backtrace;
822+
expr
823+
});
824+
819825
// we want to be able to handle e.g. concat("foo", "bar")
820826
let expr = cx.expander().fold_expr(expr);
821827
match expr.node {

src/test/compile-fail/macro-expanded-include/foo/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
macro_rules! m {
1414
() => { include!("file.txt"); }
1515
}
16+
17+
macro_rules! n {
18+
() => { unsafe { asm!(include_str!("file.txt")); } }
19+
}

src/test/compile-fail/macro-expanded-include/test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(rustc_attrs)]
11+
#![feature(asm, rustc_attrs)]
12+
#![allow(unused)]
1213

1314
#[macro_use]
1415
mod foo;
1516

1617
m!();
18+
fn f() { n!(); }
1719

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

0 commit comments

Comments
 (0)