@@ -503,13 +503,16 @@ pub enum NonNarrowChar {
503
503
ZeroWidth ( BytePos ) ,
504
504
/// Represents a wide (fullwidth) character
505
505
Wide ( BytePos ) ,
506
+ /// Represents a tab character, represented visually with a width of 4 characters
507
+ Tab ( BytePos ) ,
506
508
}
507
509
508
510
impl NonNarrowChar {
509
511
fn new ( pos : BytePos , width : usize ) -> Self {
510
512
match width {
511
513
0 => NonNarrowChar :: ZeroWidth ( pos) ,
512
514
2 => NonNarrowChar :: Wide ( pos) ,
515
+ 4 => NonNarrowChar :: Tab ( pos) ,
513
516
_ => panic ! ( "width {} given for non-narrow character" , width) ,
514
517
}
515
518
}
@@ -518,7 +521,8 @@ impl NonNarrowChar {
518
521
pub fn pos ( & self ) -> BytePos {
519
522
match * self {
520
523
NonNarrowChar :: ZeroWidth ( p) |
521
- NonNarrowChar :: Wide ( p) => p,
524
+ NonNarrowChar :: Wide ( p) |
525
+ NonNarrowChar :: Tab ( p) => p,
522
526
}
523
527
}
524
528
@@ -527,6 +531,7 @@ impl NonNarrowChar {
527
531
match * self {
528
532
NonNarrowChar :: ZeroWidth ( _) => 0 ,
529
533
NonNarrowChar :: Wide ( _) => 2 ,
534
+ NonNarrowChar :: Tab ( _) => 4 ,
530
535
}
531
536
}
532
537
}
@@ -538,6 +543,7 @@ impl Add<BytePos> for NonNarrowChar {
538
543
match self {
539
544
NonNarrowChar :: ZeroWidth ( pos) => NonNarrowChar :: ZeroWidth ( pos + rhs) ,
540
545
NonNarrowChar :: Wide ( pos) => NonNarrowChar :: Wide ( pos + rhs) ,
546
+ NonNarrowChar :: Tab ( pos) => NonNarrowChar :: Tab ( pos + rhs) ,
541
547
}
542
548
}
543
549
}
@@ -549,6 +555,7 @@ impl Sub<BytePos> for NonNarrowChar {
549
555
match self {
550
556
NonNarrowChar :: ZeroWidth ( pos) => NonNarrowChar :: ZeroWidth ( pos - rhs) ,
551
557
NonNarrowChar :: Wide ( pos) => NonNarrowChar :: Wide ( pos - rhs) ,
558
+ NonNarrowChar :: Tab ( pos) => NonNarrowChar :: Tab ( pos - rhs) ,
552
559
}
553
560
}
554
561
}
@@ -868,8 +875,10 @@ impl FileMap {
868
875
869
876
pub fn record_width ( & self , pos : BytePos , ch : char ) {
870
877
let width = match ch {
871
- '\t' | '\n' =>
872
- // Tabs will consume one column.
878
+ '\t' =>
879
+ // Tabs will consume 4 columns.
880
+ 4 ,
881
+ '\n' =>
873
882
// Make newlines take one column so that displayed spans can point them.
874
883
1 ,
875
884
ch =>
0 commit comments