1
Fork 0

new_source_file no longer enters duplicate files, expand_include_bytes includes the source if it can convert bytes to string

This commit is contained in:
Matthew Russo 2018-10-30 10:10:42 -04:00
parent 906deae079
commit 6ee4d3cafc
2 changed files with 40 additions and 19 deletions

View file

@ -182,9 +182,12 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke
DummyResult::expr(sp)
}
Ok(..) => {
// Add this input file to the code map to make it available as
// dependency information, but don't enter it's contents
cx.source_map().new_source_file(file.into(), String::new());
let src = match String::from_utf8(bytes.clone()) {
Ok(contents) => contents,
Err(..) => "".to_string()
};
cx.source_map().new_source_file(file.into(), src);
base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes))))
}