diff options
| author | bors <bors@rust-lang.org> | 2021-01-12 08:38:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-12 08:38:47 +0000 |
| commit | b6b461652a9bebfb4ddabcae896ee7237cf0962a (patch) | |
| tree | caa08d5e6f97757f4e3ba0fc5bc5879258d298ed /compiler/rustc_errors/src/styled_buffer.rs | |
| parent | 8234db5bc7b122dd9e39d738c30bcae005a96568 (diff) | |
| parent | 139daf564e47eae5c44445e959122ea5f80bb128 (diff) | |
| download | rust-b6b461652a9bebfb4ddabcae896ee7237cf0962a.tar.gz rust-b6b461652a9bebfb4ddabcae896ee7237cf0962a.zip | |
Auto merge of #80939 - JohnTitor:rollup-pymns4q, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #79757 (Replace tabs earlier in diagnostics) - #80600 (Add `MaybeUninit` method `array_assume_init`) - #80880 (Move some tests to more reasonable directories) - #80897 (driver: Use `atty` instead of rolling our own) - #80898 (Add another test case for #79808) - #80917 (core/slice: remove doc comment about scoped borrow) - #80927 (Replace a simple `if let` with the `matches` macro) - #80930 (fix typo in trait method mutability mismatch help) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src/styled_buffer.rs')
| -rw-r--r-- | compiler/rustc_errors/src/styled_buffer.rs | 27 |
1 files changed, 3 insertions, 24 deletions
diff --git a/compiler/rustc_errors/src/styled_buffer.rs b/compiler/rustc_errors/src/styled_buffer.rs index f2d255d7d95..a4dd0f391bd 100644 --- a/compiler/rustc_errors/src/styled_buffer.rs +++ b/compiler/rustc_errors/src/styled_buffer.rs @@ -13,34 +13,13 @@ impl StyledBuffer { StyledBuffer { text: vec![], styles: vec![] } } - fn replace_tabs(&mut self) { - 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' { - 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); - } - } - } - } + pub fn render(&self) -> Vec<Vec<StyledString>> { + // Tabs are assumed to have been replaced by spaces in calling code. + assert!(self.text.iter().all(|r| !r.contains(&'\t'))); - pub fn render(&mut self) -> Vec<Vec<StyledString>> { let mut output: Vec<Vec<StyledString>> = vec![]; let mut styled_vec: Vec<StyledString> = vec![]; - // before we render, replace tabs with spaces - self.replace_tabs(); - for (row, row_style) in self.text.iter().zip(&self.styles) { let mut current_style = Style::NoStyle; let mut current_text = String::new(); |
