Skip to content

Commit

Permalink
Auto merge of #33513 - sanxiyn:tab-in-error, r=nikomatsakis
Browse files Browse the repository at this point in the history
Better handling of tab in error

cc #33240.
  • Loading branch information
bors committed May 13, 2016
2 parents a581c82 + c331032 commit edb6f83
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/libsyntax/errors/snippet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,15 @@ impl StyledBuffer {
self.text[line][col] = chr;
self.styles[line][col] = style;
} else {
while self.text[line].len() < col {
self.text[line].push(' ');
let mut i = self.text[line].len();
while i < col {
let s = match self.text[0].get(i) {
Some(&'\t') => '\t',
_ => ' '
};
self.text[line].push(s);
self.styles[line].push(Style::NoStyle);
i += 1;
}
self.text[line].push(chr);
self.styles[line].push(style);
Expand Down
24 changes: 24 additions & 0 deletions src/libsyntax/errors/snippet/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ fn make_string(lines: &[RenderedLine]) -> String {
.collect()
}

#[test]
fn tab() {
let file_text = "
fn foo() {
\tbar;
}
";

let cm = Rc::new(CodeMap::new());
let foo = cm.new_filemap_and_lines("foo.rs", file_text);
let span_bar = cm.span_substr(&foo, file_text, "bar", 0);

let mut snippet = SnippetData::new(cm, Some(span_bar));
snippet.push(span_bar, true, None);

let lines = snippet.render_lines();
let text = make_string(&lines);
assert_eq!(&text[..], &"
--> foo.rs:3:2
3 |> \tbar;
|> \t^^^
"[1..]);
}

#[test]
fn one_line() {
let file_text = r#"
Expand Down

0 comments on commit edb6f83

Please sign in to comment.