Skip to content

Commit 97005c0

Browse files
committed
auto merge of #11401 : michaelwoerister/rust/issue11322, r=alexcrichton
`expand_include_str()` in libsyntax seems to have corrupted the CodeMap by always setting the BytePos of any included files to zero. It now uses `CodeMap::new_filemap()` which should set everything properly. This should fix issue #11322 but I don't want to close it before I have confirmation from the reporters that the problem is indeed fixed.
2 parents 430652c + ad3a179 commit 97005c0

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed

src/libsyntax/ext/source_util.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use parse;
1919
use parse::token::{get_ident_interner};
2020
use print::pprust;
2121

22-
use std::cell::RefCell;
2322
use std::io;
2423
use std::io::File;
2524
use std::str;
@@ -105,20 +104,14 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
105104
Ok(bytes) => bytes,
106105
};
107106
match str::from_utf8_owned_opt(bytes) {
108-
Some(s) => {
109-
let s = s.to_managed();
107+
Some(src) => {
110108
// Add this input file to the code map to make it available as
111109
// dependency information
112-
let mut files = cx.parse_sess.cm.files.borrow_mut();
113-
files.get().push(@codemap::FileMap {
114-
name: file.display().to_str().to_managed(),
115-
substr: codemap::FssNone,
116-
src: s,
117-
start_pos: codemap::BytePos(0),
118-
lines: RefCell::new(~[]),
119-
multibyte_chars: RefCell::new(~[]),
120-
});
121-
base::MRExpr(cx.expr_str(sp, s))
110+
let src = src.to_managed();
111+
let filename = file.display().to_str().to_managed();
112+
cx.parse_sess.cm.new_filemap(filename, src);
113+
114+
base::MRExpr(cx.expr_str(sp, src))
122115
}
123116
None => {
124117
cx.span_fatal(sp, format!("{} wasn't a utf-8 file", file.display()));

src/test/debug-info/include_string.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2013 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+
// xfail-android: FIXME(#10381)
12+
13+
// compile-flags:-Z extra-debug-info
14+
// debugger:rbreak zzz
15+
// debugger:run
16+
// debugger:finish
17+
// debugger:print string1
18+
// check:$1 = [...]"some text to include in another file as string 1", length = 48}
19+
// debugger:print string2
20+
// check:$2 = [...]"some text to include in another file as string 2", length = 48}
21+
// debugger:print string3
22+
// check:$3 = [...]"some text to include in another file as string 3", length = 48}
23+
// debugger:continue
24+
25+
#[allow(unused_variable)];
26+
27+
// This test case makes sure that debug info does not ICE when include_str is
28+
// used multiple times (see issue #11322).
29+
30+
fn main() {
31+
let string1 = include_str!("text-to-include-1.txt");
32+
let string2 = include_str!("text-to-include-2.txt");
33+
let string3 = include_str!("text-to-include-3.txt");
34+
zzz();
35+
}
36+
37+
fn zzz() {()}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some text to include in another file as string 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some text to include in another file as string 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some text to include in another file as string 3

0 commit comments

Comments
 (0)