@@ -642,6 +642,21 @@ impl CodeMap {
642
642
filemap
643
643
}
644
644
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
+
645
660
/// Allocates a new FileMap representing a source file from an external
646
661
/// crate. The source code of such an "imported filemap" is not available,
647
662
/// but we still know enough to generate accurate debuginfo location
@@ -1190,27 +1205,14 @@ mod tests {
1190
1205
Span { lo : BytePos ( left_index) , hi : BytePos ( right_index + 1 ) , expn_id : NO_EXPANSION }
1191
1206
}
1192
1207
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
-
1206
1208
/// Test span_to_snippet and span_to_lines for a span coverting 3
1207
1209
/// lines in the middle of a file.
1208
1210
#[ test]
1209
1211
fn span_to_snippet_and_lines_spanning_multiple_lines ( ) {
1210
1212
let cm = CodeMap :: new ( ) ;
1211
1213
let inputtext = "aaaaa\n bbbbBB\n CCC\n DDDDDddddd\n eee\n " ;
1212
1214
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) ;
1214
1216
let span = span_from_selection ( inputtext, selection) ;
1215
1217
1216
1218
// check that we are extracting the text we thought we were extracting
0 commit comments