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/librustc_errors/styled_buffer.rs | |
| parent | 71da1c21ebc79f19e749344c8b4e2c13f533872e (diff) | |
| download | rust-9d80e2200af22bb4532a7cc4738b22e408072ffd.tar.gz rust-9d80e2200af22bb4532a7cc4738b22e408072ffd.zip | |
Display `\t` in diagnostics code as four spaces
Diffstat (limited to 'src/librustc_errors/styled_buffer.rs')
| -rw-r--r-- | src/librustc_errors/styled_buffer.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/librustc_errors/styled_buffer.rs b/src/librustc_errors/styled_buffer.rs index ceb94f27dc3..2c33f805203 100644 --- a/src/librustc_errors/styled_buffer.rs +++ b/src/librustc_errors/styled_buffer.rs @@ -27,10 +27,21 @@ impl StyledBuffer { } fn replace_tabs(&mut self) { - for line in self.text.iter_mut() { - for c in line.iter_mut() { + for (line_pos, line) in self.text.iter_mut().enumerate() { + let mut tab_pos = vec![]; + for (pos, c) in line.iter().enumerate() { if *c == '\t' { - *c = ' '; + tab_pos.push(pos); + } + } + // start with the tabs at the end of the line to replace them with 4 space chars + for pos in tab_pos.iter().rev() { + assert_eq!(line.remove(*pos), '\t'); + // fix the position of the style to match up after replacing the tabs + let s = self.styles[line_pos].remove(*pos); + for _ in 0..4 { + line.insert(*pos, ' '); + self.styles[line_pos].insert(*pos, s); } } } |
