Skip to content

Commit bd459c2

Browse files
committed
Auto merge of #122029 - estebank:drive-by-ui-test, r=oli-obk
When displaying multispans, ignore empty lines adjacent to `...` ``` error[E0308]: `match` arms have incompatible types --> tests/ui/codemap_tests/huge_multispan_highlight.rs:98:18 | 6 | let _ = match true { | ---------- `match` arms have incompatible types 7 | true => ( | _________________- 8 | | // last line shown in multispan header ... | 96 | | 97 | | ), | |_________- this is found to be of type `()` 98 | false => " | __________________^ ... | 119 | | 120 | | ", | |_________^ expected `()`, found `&str` error[E0308]: `match` arms have incompatible types --> tests/ui/codemap_tests/huge_multispan_highlight.rs:215:18 | 122 | let _ = match true { | ---------- `match` arms have incompatible types 123 | true => ( | _________________- 124 | | 125 | | 1 // last line shown in multispan header ... | 213 | | 214 | | ), | |_________- this is found to be of type `{integer}` 215 | false => " | __________________^ 216 | | 217 | | 218 | | 1 last line shown in multispan ... | 237 | | 238 | | ", | |_________^ expected integer, found `&str` ```
2 parents a7e4de1 + 957c0d3 commit bd459c2

15 files changed

+323
-35
lines changed

compiler/rustc_errors/src/emitter.rs

+48-1
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,27 @@ impl HumanEmitter {
16381638
*style,
16391639
);
16401640
}
1641+
if let Some(line) = annotated_file.lines.get(line_idx) {
1642+
for ann in &line.annotations {
1643+
if let AnnotationType::MultilineStart(pos) = ann.annotation_type
1644+
{
1645+
// In the case where we have elided the entire start of the
1646+
// multispan because those lines were empty, we still need
1647+
// to draw the `|`s across the `...`.
1648+
draw_multiline_line(
1649+
&mut buffer,
1650+
last_buffer_line_num,
1651+
width_offset,
1652+
pos,
1653+
if ann.is_primary {
1654+
Style::UnderlinePrimary
1655+
} else {
1656+
Style::UnderlineSecondary
1657+
},
1658+
);
1659+
}
1660+
}
1661+
}
16411662
} else if line_idx_delta == 2 {
16421663
let unannotated_line = annotated_file
16431664
.file
@@ -1665,6 +1686,24 @@ impl HumanEmitter {
16651686
*style,
16661687
);
16671688
}
1689+
if let Some(line) = annotated_file.lines.get(line_idx) {
1690+
for ann in &line.annotations {
1691+
if let AnnotationType::MultilineStart(pos) = ann.annotation_type
1692+
{
1693+
draw_multiline_line(
1694+
&mut buffer,
1695+
last_buffer_line_num,
1696+
width_offset,
1697+
pos,
1698+
if ann.is_primary {
1699+
Style::UnderlinePrimary
1700+
} else {
1701+
Style::UnderlineSecondary
1702+
},
1703+
);
1704+
}
1705+
}
1706+
}
16681707
}
16691708
}
16701709

@@ -2417,7 +2456,15 @@ impl FileWithAnnotatedLines {
24172456
// the beginning doesn't have an underline, but the current logic seems to be
24182457
// working correctly.
24192458
let middle = min(ann.line_start + 4, ann.line_end);
2420-
for line in ann.line_start + 1..middle {
2459+
// We'll show up to 4 lines past the beginning of the multispan start.
2460+
// We will *not* include the tail of lines that are only whitespace.
2461+
let until = (ann.line_start..middle)
2462+
.rev()
2463+
.filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s)))
2464+
.find(|(_, s)| !s.trim().is_empty())
2465+
.map(|(line, _)| line)
2466+
.unwrap_or(ann.line_start);
2467+
for line in ann.line_start + 1..until {
24212468
// Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
24222469
add_annotation_to_file(&mut output, file.clone(), line, ann.as_line());
24232470
}

compiler/rustc_expand/src/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ error: foo
276276
|
277277
2 | fn foo() {
278278
| __________^
279-
3 | |
280-
4 | |
279+
... |
281280
5 | | }
282281
| |___^ test
283282

src/tools/clippy/tests/ui/async_yields_async.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ LL | let _m = async || {
8181
| _______________________-
8282
LL | | println!("I'm bored");
8383
LL | | // Some more stuff
84-
LL | |
85-
LL | | // Finally something to await
84+
... |
8685
LL | | CustomFutureType
8786
| | ^^^^^^^^^^^^^^^^
8887
| | |

src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ error: found an empty line after an outer attribute. Perhaps you forgot to add a
2222
--> tests/ui/empty_line_after_outer_attribute.rs:28:1
2323
|
2424
LL | / #[crate_type = "lib"]
25-
LL | |
26-
LL | |
25+
... |
2726
LL | | fn with_two_newlines() { assert!(true) }
2827
| |_
2928

src/tools/compiletest/src/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4040,7 +4040,7 @@ impl<'test> TestCx<'test> {
40404040
};
40414041

40424042
let stderr = if force_color_svg {
4043-
anstyle_svg::Term::new().render_svg(&proc_res.stderr)
4043+
anstyle_svg::Term::new().min_width_px(730).render_svg(&proc_res.stderr)
40444044
} else if explicit_format {
40454045
proc_res.stderr.clone()
40464046
} else {

tests/rustdoc-ui/lints/check.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ warning: missing documentation for the crate
44
LL | / #![feature(rustdoc_missing_doc_code_examples)]
55
LL | |
66
LL | |
7-
LL | |
87
... |
98
LL | |
109
LL | | pub fn foo() {}
@@ -39,7 +38,6 @@ warning: missing code example in this documentation
3938
LL | / #![feature(rustdoc_missing_doc_code_examples)]
4039
LL | |
4140
LL | |
42-
LL | |
4341
... |
4442
LL | |
4543
LL | | pub fn foo() {}

tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ LL | v.call(|(), this: &mut S| {
4242
| |
4343
LL | |
4444
LL | |
45-
LL | |
46-
LL | | _ = v;
45+
... |
4746
LL | | v.set();
4847
| | - first borrow occurs due to use of `v` in closure
4948
... |

tests/ui/codemap_tests/huge_multispan_highlight.rs

+151-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
//@ compile-flags: --error-format=human --color=always
2+
//@ ignore-windows
3+
// Temporary until next release:
4+
//@ ignore-stage2
15
fn main() {
2-
let x = "foo";
6+
let _ = match true {
7+
true => (
8+
// last line shown in multispan header
39

410

511

@@ -87,5 +93,148 @@ fn main() {
8793

8894

8995

90-
let y = &mut x; //~ ERROR cannot borrow
96+
97+
),
98+
false => "
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
",
121+
};
122+
let _ = match true {
123+
true => (
124+
125+
1 // last line shown in multispan header
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+
200+
201+
202+
203+
204+
205+
206+
207+
208+
209+
210+
211+
212+
213+
214+
),
215+
false => "
216+
217+
218+
1 last line shown in multispan
219+
220+
221+
222+
223+
224+
225+
226+
227+
228+
229+
230+
231+
232+
233+
234+
235+
236+
237+
238+
",
239+
};
91240
}

tests/ui/codemap_tests/huge_multispan_highlight.stderr

-14
This file was deleted.

0 commit comments

Comments
 (0)