@@ -436,9 +436,11 @@ fn highlight_lines(err: &mut EmitterWriter,
436
436
elided = true ;
437
437
}
438
438
// 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
+ }
442
444
}
443
445
if elided {
444
446
let last_line = display_lines[ display_lines. len ( ) - 1 u] ;
@@ -465,24 +467,26 @@ fn highlight_lines(err: &mut EmitterWriter,
465
467
for _ in range ( 0 , skip) {
466
468
s. push ( ' ' ) ;
467
469
}
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
+ }
479
482
}
483
+
480
484
try!( write ! ( & mut err. dst, "{}" , s) ) ;
481
485
let mut s = String :: from_str ( "^" ) ;
482
486
let hi = cm. lookup_char_pos ( sp. hi ) ;
483
487
if hi. col != lo. col {
484
488
// 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;
486
490
for _ in range ( 0 , num_squigglies) {
487
491
s. push ( '~' ) ;
488
492
}
@@ -510,16 +514,22 @@ fn custom_highlight_lines(w: &mut EmitterWriter,
510
514
511
515
let lines = lines. lines . as_slice ( ) ;
512
516
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
+ }
515
521
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) {
521
524
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
+ }
523
533
}
524
534
}
525
535
let last_line_start = format ! ( "{}:{} " , fm. name, lines[ lines. len( ) -1 ] +1 ) ;
0 commit comments