File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
src/libsyntax/errors/snippet Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -312,9 +312,15 @@ impl StyledBuffer {
312312 self . text [ line] [ col] = chr;
313313 self . styles [ line] [ col] = style;
314314 } else {
315- while self . text [ line] . len ( ) < col {
316- self . text [ line] . push ( ' ' ) ;
315+ let mut i = self . text [ line] . len ( ) ;
316+ while i < col {
317+ let s = match self . text [ 0 ] . get ( i) {
318+ Some ( & '\t' ) => '\t' ,
319+ _ => ' '
320+ } ;
321+ self . text [ line] . push ( s) ;
317322 self . styles [ line] . push ( Style :: NoStyle ) ;
323+ i += 1 ;
318324 }
319325 self . text [ line] . push ( chr) ;
320326 self . styles [ line] . push ( style) ;
Original file line number Diff line number Diff line change @@ -79,6 +79,30 @@ fn make_string(lines: &[RenderedLine]) -> String {
7979 . collect ( )
8080}
8181
82+ #[ test]
83+ fn tab ( ) {
84+ let file_text = "
85+ fn foo() {
86+ \t bar;
87+ }
88+ " ;
89+
90+ let cm = Rc :: new ( CodeMap :: new ( ) ) ;
91+ let foo = cm. new_filemap_and_lines ( "foo.rs" , file_text) ;
92+ let span_bar = cm. span_substr ( & foo, file_text, "bar" , 0 ) ;
93+
94+ let mut snippet = SnippetData :: new ( cm, Some ( span_bar) ) ;
95+ snippet. push ( span_bar, true , None ) ;
96+
97+ let lines = snippet. render_lines ( ) ;
98+ let text = make_string ( & lines) ;
99+ assert_eq ! ( & text[ ..] , & "
100+ --> foo.rs:3:2
101+ 3 |> \t bar;
102+ |> \t ^^^
103+ " [ 1 ..] ) ;
104+ }
105+
82106#[ test]
83107fn one_line ( ) {
84108 let file_text = r#"
You can’t perform that action at this time.
0 commit comments