@@ -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\n bbbbBB\n CCC\n DDDDDddddd\n eee\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
0 commit comments