diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2017-11-12 22:06:00 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2017-11-24 08:24:31 -0800 |
| commit | 9d80e2200af22bb4532a7cc4738b22e408072ffd (patch) | |
| tree | d0bb516d90d8888abac87d9c64f1c65b98e8139f /src/libsyntax_pos/lib.rs | |
| parent | 71da1c21ebc79f19e749344c8b4e2c13f533872e (diff) | |
| download | rust-9d80e2200af22bb4532a7cc4738b22e408072ffd.tar.gz rust-9d80e2200af22bb4532a7cc4738b22e408072ffd.zip | |
Display `\t` in diagnostics code as four spaces
Diffstat (limited to 'src/libsyntax_pos/lib.rs')
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 47755dc1d54..281b698e71d 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -503,6 +503,8 @@ pub enum NonNarrowChar { ZeroWidth(BytePos), /// Represents a wide (fullwidth) character Wide(BytePos), + /// Represents a tab character, represented visually with a width of 4 characters + Tab(BytePos), } impl NonNarrowChar { @@ -510,6 +512,7 @@ impl NonNarrowChar { match width { 0 => NonNarrowChar::ZeroWidth(pos), 2 => NonNarrowChar::Wide(pos), + 4 => NonNarrowChar::Tab(pos), _ => panic!("width {} given for non-narrow character", width), } } @@ -518,7 +521,8 @@ impl NonNarrowChar { pub fn pos(&self) -> BytePos { match *self { NonNarrowChar::ZeroWidth(p) | - NonNarrowChar::Wide(p) => p, + NonNarrowChar::Wide(p) | + NonNarrowChar::Tab(p) => p, } } @@ -527,6 +531,7 @@ impl NonNarrowChar { match *self { NonNarrowChar::ZeroWidth(_) => 0, NonNarrowChar::Wide(_) => 2, + NonNarrowChar::Tab(_) => 4, } } } @@ -538,6 +543,7 @@ impl Add<BytePos> for NonNarrowChar { match self { NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos + rhs), NonNarrowChar::Wide(pos) => NonNarrowChar::Wide(pos + rhs), + NonNarrowChar::Tab(pos) => NonNarrowChar::Tab(pos + rhs), } } } @@ -549,6 +555,7 @@ impl Sub<BytePos> for NonNarrowChar { match self { NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos - rhs), NonNarrowChar::Wide(pos) => NonNarrowChar::Wide(pos - rhs), + NonNarrowChar::Tab(pos) => NonNarrowChar::Tab(pos - rhs), } } } @@ -868,8 +875,10 @@ impl FileMap { pub fn record_width(&self, pos: BytePos, ch: char) { let width = match ch { - '\t' | '\n' => - // Tabs will consume one column. + '\t' => + // Tabs will consume 4 columns. + 4, + '\n' => // Make newlines take one column so that displayed spans can point them. 1, ch => |
