Skip to content

Commit 1fd014a

Browse files
author
Jonathan Turner
committedJul 14, 2016
Add fix for tabs. Move error unit tests->ui tests
1 parent 2e8e73c commit 1fd014a

17 files changed

+414
-772
lines changed
 

‎src/librustc_errors/styled_buffer.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,27 @@ impl StyledBuffer {
2626
}
2727
}
2828

29-
pub fn render(&self) -> Vec<Vec<StyledString>> {
29+
pub fn copy_tabs(&mut self, row: usize) {
30+
if row < self.text.len() {
31+
for i in row+1..self.text.len() {
32+
for j in 0..self.text[i].len() {
33+
if self.text[row].len() > j &&
34+
self.text[row][j] == '\t' &&
35+
self.text[i][j] == ' ' {
36+
self.text[i][j] = '\t';
37+
}
38+
}
39+
}
40+
}
41+
}
42+
43+
pub fn render(&mut self) -> Vec<Vec<StyledString>> {
3044
let mut output: Vec<Vec<StyledString>> = vec![];
3145
let mut styled_vec: Vec<StyledString> = vec![];
3246

47+
//before we render, do a little patch-up work to support tabs
48+
self.copy_tabs(3);
49+
3350
for (row, row_style) in self.text.iter().zip(&self.styles) {
3451
let mut current_style = Style::NoStyle;
3552
let mut current_text = String::new();
@@ -78,11 +95,7 @@ impl StyledBuffer {
7895
} else {
7996
let mut i = self.text[line].len();
8097
while i < col {
81-
let s = match self.text[0].get(i) {
82-
Some(&'\t') => '\t',
83-
_ => ' ',
84-
};
85-
self.text[line].push(s);
98+
self.text[line].push(' ');
8699
self.styles[line].push(Style::NoStyle);
87100
i += 1;
88101
}

‎src/libsyntax/codemap.rs

Lines changed: 4 additions & 766 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// rustc-env:RUST_NEW_ERROR_FORMAT
12+
#![feature(optin_builtin_traits)]
13+
fn main() {
14+
struct Foo;
15+
16+
impl !Sync for Foo {}
17+
18+
unsafe impl Send for &'static Foo { }
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`, can only be implemented for a struct/enum type, not `&'static main::Foo`
2+
--> $DIR/empty_span.rs:18:5
3+
|
4+
18 | unsafe impl Send for &'static Foo { }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// rustc-env:RUST_NEW_ERROR_FORMAT
12+
13+
fn main() {
14+
let x = "foo";
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
let y = &mut x;
101+
}
102+
103+
104+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: cannot borrow immutable local variable `x` as mutable
2+
--> $DIR/huge_multispan_highlight.rs:100:18
3+
|
4+
14 | let x = "foo";
5+
| - use `mut x` here to make mutable
6+
...
7+
100 | let y = &mut x;
8+
| ^ cannot borrow mutably
9+
10+
error: aborting due to previous error
11+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// rustc-env:RUST_NEW_ERROR_FORMAT
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
fn main() {
98+
let mut x = "foo";
99+
let y = &mut x;
100+
let z = &mut x;
101+
}
102+
103+
104+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0499]: cannot borrow `x` as mutable more than once at a time
2+
--> $DIR/issue-11715.rs:100:18
3+
|
4+
99 | let y = &mut x;
5+
| - first mutable borrow occurs here
6+
100 | let z = &mut x;
7+
| ^ second mutable borrow occurs here
8+
101 | }
9+
| - first borrow ends here
10+
11+
error: aborting due to previous error
12+

‎src/test/ui/codemap_tests/one_line.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// rustc-env:RUST_NEW_ERROR_FORMAT
12+
13+
fn main() {
14+
let mut v = vec![Some("foo"), Some("bar")];
15+
v.push(v.pop().unwrap());
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0499]: cannot borrow `v` as mutable more than once at a time
2+
--> $DIR/one_line.rs:15:12
3+
|
4+
15 | v.push(v.pop().unwrap());
5+
| - ^ - first borrow ends here
6+
| | |
7+
| | second mutable borrow occurs here
8+
| first mutable borrow occurs here
9+
10+
error: aborting due to previous error
11+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// rustc-env:RUST_NEW_ERROR_FORMAT
12+
#[derive(Debug)]
13+
struct Foo { }
14+
15+
struct S {f:String}
16+
impl Drop for S {
17+
fn drop(&mut self) { println!("{}", self.f); }
18+
}
19+
20+
fn main() {
21+
match (S {f:"foo".to_string()}) {
22+
S {f:_s} => {}
23+
}
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0509]: cannot move out of type `S`, which implements the `Drop` trait
2+
--> $DIR/overlapping_spans.rs:22:9
3+
|
4+
22 | S {f:_s} => {}
5+
| ^^^^^--^
6+
| | |
7+
| | hint: to prevent move, use `ref _s` or `ref mut _s`
8+
| cannot move out of here
9+
10+
error: aborting due to previous error
11+

‎src/test/ui/codemap_tests/tab.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// rustc-env:RUST_NEW_ERROR_FORMAT
12+
// ignore-tidy-tab
13+
fn main() {
14+
bar;
15+
}
16+

‎src/test/ui/codemap_tests/tab.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error[E0425]: unresolved name `bar`
2+
--> $DIR/tab.rs:14:2
3+
|
4+
14 | \tbar;
5+
| \t^^^
6+
7+
error: aborting due to previous error
8+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// rustc-env:RUST_NEW_ERROR_FORMAT
12+
include!("two_files_data.rs");
13+
14+
struct Baz { }
15+
16+
impl Bar for Baz { }
17+
18+
fn main() { }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0404]: `Bar` is not a trait
2+
--> $DIR/two_files.rs:16:6
3+
|
4+
16 | impl Bar for Baz { }
5+
| ^^^ `Bar` is not a trait
6+
|
7+
::: $DIR/two_files_data.rs
8+
|
9+
15 | type Bar = Foo;
10+
| --------------- type aliases cannot be used for traits
11+
12+
error: cannot continue compilation due to previous error
13+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// rustc-env:RUST_NEW_ERROR_FORMAT
12+
// ignore-test
13+
trait Foo { }
14+
15+
type Bar = Foo;
16+

0 commit comments

Comments
 (0)
Please sign in to comment.