Skip to content

Commit fb7fdf3

Browse files
committed
---
yaml --- r: 228551 b: refs/heads/try c: 0e907fa h: refs/heads/master i: 228549: 2059683 228547: 993b92b 228543: 89d2dcf v: v3
1 parent 42f867f commit fb7fdf3

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 007246c17f1891cabb84c8a82250703f542cd58e
4+
refs/heads/try: 0e907fa542d7bfa08ca1f55512ffa4a5ff70ed15
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/libsyntax/codemap.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,21 @@ impl CodeMap {
642642
filemap
643643
}
644644

645+
/// Creates a new filemap and sets its line information.
646+
pub fn new_filemap_and_lines(&self, filename: &str, src: &str) -> Rc<FileMap> {
647+
let fm = self.new_filemap(filename.to_string(), src.to_owned());
648+
let mut byte_pos: u32 = 0;
649+
for line in src.lines() {
650+
// register the start of this line
651+
fm.next_line(BytePos(byte_pos));
652+
653+
// update byte_pos to include this line and the \n at the end
654+
byte_pos += line.len() as u32 + 1;
655+
}
656+
fm
657+
}
658+
659+
645660
/// Allocates a new FileMap representing a source file from an external
646661
/// crate. The source code of such an "imported filemap" is not available,
647662
/// but we still know enough to generate accurate debuginfo location
@@ -1190,27 +1205,14 @@ mod tests {
11901205
Span { lo: BytePos(left_index), hi: BytePos(right_index + 1), expn_id: NO_EXPANSION }
11911206
}
11921207

1193-
fn new_filemap_and_lines(cm: &CodeMap, filename: &str, input: &str) -> Rc<FileMap> {
1194-
let fm = cm.new_filemap(filename.to_string(), input.to_string());
1195-
let mut byte_pos: u32 = 0;
1196-
for line in input.lines() {
1197-
// register the start of this line
1198-
fm.next_line(BytePos(byte_pos));
1199-
1200-
// update byte_pos to include this line and the \n at the end
1201-
byte_pos += line.len() as u32 + 1;
1202-
}
1203-
fm
1204-
}
1205-
12061208
/// Test span_to_snippet and span_to_lines for a span coverting 3
12071209
/// lines in the middle of a file.
12081210
#[test]
12091211
fn span_to_snippet_and_lines_spanning_multiple_lines() {
12101212
let cm = CodeMap::new();
12111213
let inputtext = "aaaaa\nbbbbBB\nCCC\nDDDDDddddd\neee\n";
12121214
let selection = " \n ^~\n~~~\n~~~~~ \n \n";
1213-
new_filemap_and_lines(&cm, "blork.rs", inputtext);
1215+
cm.new_filemap_and_lines("blork.rs", inputtext);
12141216
let span = span_from_selection(inputtext, selection);
12151217

12161218
// check that we are extracting the text we thought we were extracting

branches/try/src/libsyntax/diagnostic.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,7 @@ mod test {
837837
tolv
838838
dreizehn
839839
";
840-
let file = cm.new_filemap("dummy.txt".to_string(), content.to_string());
841-
for (i, b) in content.bytes().enumerate() {
842-
if b == b'\n' {
843-
file.next_line(BytePos(i as u32));
844-
}
845-
}
840+
let file = cm.new_filemap_and_lines("dummy.txt", content);
846841
let start = file.lines.borrow()[7];
847842
let end = file.lines.borrow()[11];
848843
let sp = mk_sp(start, end);

branches/try/src/libsyntax/ext/source_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
156156
// dependency information
157157
let filename = format!("{}", file.display());
158158
let interned = token::intern_and_get_ident(&src[..]);
159-
cx.codemap().new_filemap(filename, src);
159+
cx.codemap().new_filemap_and_lines(&filename, &src);
160160

161161
base::MacEager::expr(cx.expr_str(sp, interned))
162162
}
@@ -187,7 +187,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
187187
// Add this input file to the code map to make it available as
188188
// dependency information, but don't enter it's contents
189189
let filename = format!("{}", file.display());
190-
cx.codemap().new_filemap(filename, "".to_string());
190+
cx.codemap().new_filemap_and_lines(&filename, "");
191191

192192
base::MacEager::expr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
193193
}

0 commit comments

Comments
 (0)