@@ -644,6 +644,8 @@ impl EmitterWriter {
644
644
code_offset : usize ,
645
645
margin : Margin ,
646
646
) {
647
+ // Tabs are assumed to have been replaced by spaces in calling code.
648
+ assert ! ( !source_string. contains( '\t' ) ) ;
647
649
let line_len = source_string. len ( ) ;
648
650
// Create the source line we will highlight.
649
651
let left = margin. left ( line_len) ;
@@ -707,7 +709,7 @@ impl EmitterWriter {
707
709
}
708
710
709
711
let source_string = match file. get_line ( line. line_index - 1 ) {
710
- Some ( s) => s ,
712
+ Some ( s) => replace_tabs ( & * s ) ,
711
713
None => return Vec :: new ( ) ,
712
714
} ;
713
715
@@ -1376,8 +1378,17 @@ impl EmitterWriter {
1376
1378
let file = annotated_file. file . clone ( ) ;
1377
1379
let line = & annotated_file. lines [ line_idx] ;
1378
1380
if let Some ( source_string) = file. get_line ( line. line_index - 1 ) {
1379
- let leading_whitespace =
1380
- source_string. chars ( ) . take_while ( |c| c. is_whitespace ( ) ) . count ( ) ;
1381
+ let leading_whitespace = source_string
1382
+ . chars ( )
1383
+ . take_while ( |c| c. is_whitespace ( ) )
1384
+ . map ( |c| {
1385
+ match c {
1386
+ // Tabs are displayed as 4 spaces
1387
+ '\t' => 4 ,
1388
+ _ => 1 ,
1389
+ }
1390
+ } )
1391
+ . sum ( ) ;
1381
1392
if source_string. chars ( ) . any ( |c| !c. is_whitespace ( ) ) {
1382
1393
whitespace_margin = min ( whitespace_margin, leading_whitespace) ;
1383
1394
}
@@ -1502,7 +1513,7 @@ impl EmitterWriter {
1502
1513
1503
1514
self . draw_line (
1504
1515
& mut buffer,
1505
- & unannotated_line,
1516
+ & replace_tabs ( & unannotated_line) ,
1506
1517
annotated_file. lines [ line_idx + 1 ] . line_index - 1 ,
1507
1518
last_buffer_line_num,
1508
1519
width_offset,
@@ -1598,7 +1609,7 @@ impl EmitterWriter {
1598
1609
) ;
1599
1610
// print the suggestion
1600
1611
draw_col_separator ( & mut buffer, row_num, max_line_num_len + 1 ) ;
1601
- buffer. append ( row_num, line, Style :: NoStyle ) ;
1612
+ buffer. append ( row_num, & replace_tabs ( line) , Style :: NoStyle ) ;
1602
1613
row_num += 1 ;
1603
1614
}
1604
1615
@@ -1930,6 +1941,10 @@ impl FileWithAnnotatedLines {
1930
1941
}
1931
1942
}
1932
1943
1944
+ fn replace_tabs ( str : & str ) -> String {
1945
+ str. replace ( '\t' , " " )
1946
+ }
1947
+
1933
1948
fn draw_col_separator ( buffer : & mut StyledBuffer , line : usize , col : usize ) {
1934
1949
buffer. puts ( line, col, "| " , Style :: LineNumber ) ;
1935
1950
}
0 commit comments