Skip to content

Commit 3059bb9

Browse files
authored
Auto merge of #34450 - jseyfried:fix_include_path, r=nrc
Revert a change to the relative path for macro-expanded `include!`s Fixes #34431 (c.f. discussion in that issue). r? @nrc
2 parents 15e8a67 + e488556 commit 3059bb9

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/libsyntax/ext/source_util.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
197197
fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> PathBuf {
198198
// NB: relative paths are resolved relative to the compilation unit
199199
if !arg.is_absolute() {
200-
let mut cu = PathBuf::from(&cx.codemap().span_to_filename(sp));
200+
let callsite = cx.codemap().source_callsite(sp);
201+
let mut cu = PathBuf::from(&cx.codemap().span_to_filename(callsite));
201202
cu.pop();
202203
cu.push(arg);
203204
cu

src/test/compile-fail/macro-expanded-include/file.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-test
12+
13+
macro_rules! m {
14+
() => { include!("file.txt"); }
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(rustc_attrs)]
12+
13+
#[macro_use]
14+
mod foo;
15+
16+
m!();
17+
18+
#[rustc_error]
19+
fn main() {} //~ ERROR compilation successful

0 commit comments

Comments
 (0)