-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Replace tabs earlier in diagnostics #79757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
Comment on lines
-28
to
-32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm slightly concerned by this removal. Have you tried to see the output in your local CLI? I need to double check the code, but can you confirm that the underlines are all colored correctly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
} | ||
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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Test for #78438: ensure underline alignment with many tabs on the left, long line on the right | ||
|
||
// ignore-tidy-linelength | ||
// ignore-tidy-tab | ||
|
||
fn main() { | ||
let money = 42i32; | ||
match money { | ||
v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT | ||
//~^ ERROR variable `v` is not bound in all patterns | ||
v => println!("Enough money {}", v), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0408]: variable `v` is not bound in all patterns | ||
--> $DIR/tabs-trimming.rs:9:16 | ||
| | ||
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT... | ||
jryans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - ^ ^ pattern doesn't bind `v` | ||
| | | | ||
| | pattern doesn't bind `v` | ||
| variable not in all patterns | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0408`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit heavy handed but ok with me (I will assume we'll see reports on nightly if this causes issues before it hits stable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, mostly I just wanted it to be ultra clear to future code readers which paths should not have tabs, but it could be relaxed to a comment of course. I'll check
json
output now.