@@ -436,9 +436,11 @@ fn highlight_lines(err: &mut EmitterWriter,
436436 elided = true ;
437437 }
438438 // Print the offending lines
439- for line in display_lines. iter ( ) {
440- try!( write ! ( & mut err. dst, "{}:{} {}\n " , fm. name, * line + 1 ,
441- fm. get_line( * line as int) ) ) ;
439+ for & line_number in display_lines. iter ( ) {
440+ if let Some ( line) = fm. get_line ( line_number) {
441+ try!( write ! ( & mut err. dst, "{}:{} {}\n " , fm. name,
442+ line_number + 1 , line) ) ;
443+ }
442444 }
443445 if elided {
444446 let last_line = display_lines[ display_lines. len ( ) - 1 u] ;
@@ -465,24 +467,26 @@ fn highlight_lines(err: &mut EmitterWriter,
465467 for _ in range ( 0 , skip) {
466468 s. push ( ' ' ) ;
467469 }
468- let orig = fm. get_line ( lines. lines [ 0 ] as int ) ;
469- for pos in range ( 0 u, left-skip) {
470- let cur_char = orig. as_bytes ( ) [ pos] as char ;
471- // Whenever a tab occurs on the previous line, we insert one on
472- // the error-point-squiggly-line as well (instead of a space).
473- // That way the squiggly line will usually appear in the correct
474- // position.
475- match cur_char {
476- '\t' => s. push ( '\t' ) ,
477- _ => s. push ( ' ' ) ,
478- } ;
470+ if let Some ( orig) = fm. get_line ( lines. lines [ 0 ] ) {
471+ for pos in range ( 0 u, left - skip) {
472+ let cur_char = orig. as_bytes ( ) [ pos] as char ;
473+ // Whenever a tab occurs on the previous line, we insert one on
474+ // the error-point-squiggly-line as well (instead of a space).
475+ // That way the squiggly line will usually appear in the correct
476+ // position.
477+ match cur_char {
478+ '\t' => s. push ( '\t' ) ,
479+ _ => s. push ( ' ' ) ,
480+ } ;
481+ }
479482 }
483+
480484 try!( write ! ( & mut err. dst, "{}" , s) ) ;
481485 let mut s = String :: from_str ( "^" ) ;
482486 let hi = cm. lookup_char_pos ( sp. hi ) ;
483487 if hi. col != lo. col {
484488 // the ^ already takes up one space
485- let num_squigglies = hi. col . to_uint ( ) - lo. col . to_uint ( ) - 1 u;
489+ let num_squigglies = hi. col . to_uint ( ) - lo. col . to_uint ( ) - 1 u;
486490 for _ in range ( 0 , num_squigglies) {
487491 s. push ( '~' ) ;
488492 }
@@ -510,16 +514,22 @@ fn custom_highlight_lines(w: &mut EmitterWriter,
510514
511515 let lines = lines. lines . as_slice ( ) ;
512516 if lines. len ( ) > MAX_LINES {
513- try!( write ! ( & mut w. dst, "{}:{} {}\n " , fm. name,
514- lines[ 0 ] + 1 , fm. get_line( lines[ 0 ] as int) ) ) ;
517+ if let Some ( line) = fm. get_line ( lines[ 0 ] ) {
518+ try!( write ! ( & mut w. dst, "{}:{} {}\n " , fm. name,
519+ lines[ 0 ] + 1 , line) ) ;
520+ }
515521 try!( write ! ( & mut w. dst, "...\n " ) ) ;
516- let last_line = lines[ lines. len ( ) -1 ] ;
517- try!( write ! ( & mut w. dst, "{}:{} {}\n " , fm. name,
518- last_line + 1 , fm. get_line( last_line as int) ) ) ;
519- } else {
520- for line in lines. iter ( ) {
522+ let last_line_number = lines[ lines. len ( ) - 1 ] ;
523+ if let Some ( last_line) = fm. get_line ( last_line_number) {
521524 try!( write ! ( & mut w. dst, "{}:{} {}\n " , fm. name,
522- * line + 1 , fm. get_line( * line as int) ) ) ;
525+ last_line_number + 1 , last_line) ) ;
526+ }
527+ } else {
528+ for & line_number in lines. iter ( ) {
529+ if let Some ( line) = fm. get_line ( line_number) {
530+ try!( write ! ( & mut w. dst, "{}:{} {}\n " , fm. name,
531+ line_number + 1 , line) ) ;
532+ }
523533 }
524534 }
525535 let last_line_start = format ! ( "{}:{} " , fm. name, lines[ lines. len( ) -1 ] +1 ) ;
0 commit comments