Skip to content

Commit 13ed88a

Browse files
authored
Rollup merge of rust-lang#108627 - estebank:suggestion-hightlight, r=WaffleLapkin
Properly colorize multi-part suggestions in the same line Fix rust-lang#108547.
2 parents b850cee + 6fd1751 commit 13ed88a

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

Diff for: compiler/rustc_errors/src/emitter.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ impl EmitterWriter {
18951895
self.draw_code_line(
18961896
&mut buffer,
18971897
&mut row_num,
1898-
&Vec::new(),
1898+
&[],
18991899
p + line_start,
19001900
l,
19011901
show_code_change,
@@ -1919,7 +1919,7 @@ impl EmitterWriter {
19191919
self.draw_code_line(
19201920
&mut buffer,
19211921
&mut row_num,
1922-
&Vec::new(),
1922+
&[],
19231923
p + line_start,
19241924
l,
19251925
show_code_change,
@@ -1936,7 +1936,7 @@ impl EmitterWriter {
19361936
self.draw_code_line(
19371937
&mut buffer,
19381938
&mut row_num,
1939-
&Vec::new(),
1939+
&[],
19401940
p + line_start,
19411941
l,
19421942
show_code_change,
@@ -1951,7 +1951,7 @@ impl EmitterWriter {
19511951
self.draw_code_line(
19521952
&mut buffer,
19531953
&mut row_num,
1954-
highlight_parts,
1954+
&highlight_parts,
19551955
line_pos + line_start,
19561956
line,
19571957
show_code_change,
@@ -2176,7 +2176,7 @@ impl EmitterWriter {
21762176
&self,
21772177
buffer: &mut StyledBuffer,
21782178
row_num: &mut usize,
2179-
highlight_parts: &Vec<SubstitutionHighlight>,
2179+
highlight_parts: &[SubstitutionHighlight],
21802180
line_num: usize,
21812181
line_to_add: &str,
21822182
show_code_change: DisplaySuggestion,

Diff for: compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl CodeSuggestion {
331331
});
332332
buf.push_str(&part.snippet);
333333
let cur_hi = sm.lookup_char_pos(part.span.hi());
334-
if prev_hi.line == cur_lo.line && cur_hi.line == cur_lo.line {
334+
if cur_hi.line == cur_lo.line {
335335
// Account for the difference between the width of the current code and the
336336
// snippet being suggested, so that the *later* suggestions are correctly
337337
// aligned on the screen.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags: --error-format=human --color=always
2+
// ignore-windows
3+
4+
fn short(foo_bar: &Vec<&i32>) -> &i32 { //~ ERROR missing lifetime specifier
5+
&12
6+
}
7+
8+
fn long( //~ ERROR missing lifetime specifier
9+
foo_bar: &Vec<&i32>,
10+
something_very_long_so_that_the_line_will_wrap_around__________: i32,
11+
) -> &i32 {
12+
&12
13+
}
14+
15+
fn long2( //~ ERROR missing lifetime specifier
16+
foo_bar: &Vec<&i32>) -> &i32 {
17+
&12
18+
}
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error[E0106]: missing lifetime specifier
2+
 --> $DIR/multiline-multipart-suggestion.rs:4:34
3+
 |
4+
LL | fn short(foo_bar: &Vec<&i32>) -> &i32 {
5+
 |  ---------- ^ expected named lifetime parameter
6+
 |
7+
 = help: this function's return type contains a borrowed value, but the signature does not say which one of `foo_bar`'s 2 lifetimes it is borrowed from
8+
help: consider introducing a named lifetime parameter
9+
 |
10+
LL | fn short<'a>(foo_bar: &'a Vec<&'a i32>) -> &'a i32 {
11+
 | ++++ ++ ++ ++
12+
13+
error[E0106]: missing lifetime specifier
14+
 --> $DIR/multiline-multipart-suggestion.rs:11:6
15+
 |
16+
LL |  foo_bar: &Vec<&i32>,
17+
 |  ----------
18+
LL |  something_very_long_so_that_the_line_will_wrap_around__________: i32,
19+
LL | ) -> &i32 {
20+
 |  ^ expected named lifetime parameter
21+
 |
22+
 = help: this function's return type contains a borrowed value, but the signature does not say which one of `foo_bar`'s 2 lifetimes it is borrowed from
23+
help: consider introducing a named lifetime parameter
24+
 |
25+
LL ~ fn long<'a>(
26+
LL ~  foo_bar: &'a Vec<&'a i32>,
27+
LL |  something_very_long_so_that_the_line_will_wrap_around__________: i32,
28+
LL ~ ) -> &'a i32 {
29+
 |
30+
31+
error[E0106]: missing lifetime specifier
32+
 --> $DIR/multiline-multipart-suggestion.rs:16:29
33+
 |
34+
LL |  foo_bar: &Vec<&i32>) -> &i32 {
35+
 |  ---------- ^ expected named lifetime parameter
36+
 |
37+
 = help: this function's return type contains a borrowed value, but the signature does not say which one of `foo_bar`'s 2 lifetimes it is borrowed from
38+
help: consider introducing a named lifetime parameter
39+
 |
40+
LL ~ fn long2<'a>(
41+
LL ~  foo_bar: &'a Vec<&'a i32>) -> &'a i32 {
42+
 |
43+
44+
error: aborting due to 3 previous errors
45+
46+
For more information about this error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)