Skip to content

Commit 5bd4d2e

Browse files
committed
Fix missing code map entry for uses of include_str!.
1 parent ac4dd9e commit 5bd4d2e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libsyntax/ext/source_util.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub fn expand_mod(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
8080
pub fn expand_include(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
8181
-> base::MacResult {
8282
let file = get_single_str_from_tts(cx, sp, tts, "include!");
83+
// The file will be added to the code map by the parser
8384
let p = parse::new_sub_parser_from_file(
8485
cx.parse_sess(), cx.cfg(),
8586
&res_rel_file(cx, sp, &Path::new(file)), sp);
@@ -99,7 +100,20 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
99100
Ok(bytes) => bytes,
100101
};
101102
match str::from_utf8_owned_opt(bytes) {
102-
Some(s) => base::MRExpr(cx.expr_str(sp, s.to_managed())),
103+
Some(s) => {
104+
let s = s.to_managed();
105+
// Add this input file to the code map to make it available as
106+
// dependency information
107+
cx.parse_sess.cm.files.push(@codemap::FileMap {
108+
name: file.display().to_str().to_managed(),
109+
substr: codemap::FssNone,
110+
src: s,
111+
start_pos: codemap::BytePos(0),
112+
lines: @mut ~[],
113+
multibyte_chars: @mut ~[],
114+
});
115+
base::MRExpr(cx.expr_str(sp, s))
116+
}
103117
None => {
104118
cx.span_fatal(sp, format!("{} wasn't a utf-8 file", file.display()));
105119
}

0 commit comments

Comments
 (0)