Skip to content

Commit 9cf34be

Browse files
committed
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` ```
1 parent 736eda2 commit 9cf34be

12 files changed

+231
-38
lines changed

compiler/rustc_errors/src/emitter.rs

+49-1
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,27 @@ impl HumanEmitter {
16561656
*style,
16571657
);
16581658
}
1659+
if let Some(line) = annotated_file.lines.get(line_idx) {
1660+
for ann in &line.annotations {
1661+
if let AnnotationType::MultilineStart(pos) = ann.annotation_type
1662+
{
1663+
// In the case where we have elided the entire start of the
1664+
// multispan because those lines were empty, we still need
1665+
// to draw the `|`s across the `...`.
1666+
draw_multiline_line(
1667+
&mut buffer,
1668+
last_buffer_line_num,
1669+
width_offset,
1670+
pos,
1671+
if ann.is_primary {
1672+
Style::UnderlinePrimary
1673+
} else {
1674+
Style::UnderlineSecondary
1675+
},
1676+
);
1677+
}
1678+
}
1679+
}
16591680
} else if line_idx_delta == 2 {
16601681
let unannotated_line = annotated_file
16611682
.file
@@ -1683,6 +1704,24 @@ impl HumanEmitter {
16831704
*style,
16841705
);
16851706
}
1707+
if let Some(line) = annotated_file.lines.get(line_idx) {
1708+
for ann in &line.annotations {
1709+
if let AnnotationType::MultilineStart(pos) = ann.annotation_type
1710+
{
1711+
draw_multiline_line(
1712+
&mut buffer,
1713+
last_buffer_line_num,
1714+
width_offset,
1715+
pos,
1716+
if ann.is_primary {
1717+
Style::UnderlinePrimary
1718+
} else {
1719+
Style::UnderlineSecondary
1720+
},
1721+
);
1722+
}
1723+
}
1724+
}
16861725
}
16871726
}
16881727

@@ -2435,7 +2474,16 @@ impl FileWithAnnotatedLines {
24352474
// the beginning doesn't have an underline, but the current logic seems to be
24362475
// working correctly.
24372476
let middle = min(ann.line_start + 4, ann.line_end);
2438-
for line in ann.line_start + 1..middle {
2477+
// We'll show up to 4 lines past the beginning of the multispan start.
2478+
// We will *not* include the tail of lines that are only whitespace.
2479+
let until = (ann.line_start..middle)
2480+
.rev()
2481+
.filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s)))
2482+
.filter(|(_, s)| !s.trim().is_empty())
2483+
.map(|(line, _)| line)
2484+
.next()
2485+
.unwrap_or(ann.line_start);
2486+
for line in ann.line_start + 1..until {
24392487
// Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
24402488
add_annotation_to_file(&mut output, file.clone(), line, ann.as_line());
24412489
}

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

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/associated-inherent-types/bugs/cycle-iat-inside-of-adt.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ note: cycle used when collecting item types in top-level module
3232
LL | / #![feature(inherent_associated_types)]
3333
LL | | #![allow(incomplete_features)]
3434
LL | | // FIXME(inherent_associated_types): This should pass.
35-
LL | |
3635
... |
3736
LL | |
3837
LL | | fn main() {}

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

+119
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
fn main() {
66
let _ = match true {
77
true => (
8+
// last line shown in multispan header
89

910

1011

@@ -115,6 +116,124 @@ fn main() {
115116
116117
117118
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+
118237
119238
",
120239
};

tests/ui/codemap_tests/huge_multispan_highlight.svg

+58-22
Loading

tests/ui/macros/derive-in-eager-expansion-hang.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ error: format argument must be a string literal
44
LL | / {
55
LL | | #[derive(Clone)]
66
LL | | struct S;
7-
LL | |
8-
LL | | ""
7+
... |
98
LL | | }
109
| |_____^
1110
...

tests/ui/offset-of/offset-of-tuple.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ LL | offset_of!(((u8, u16), (u32, u16, u8)), 0.2);
202202
| | in this macro invocation
203203
LL | | offset_of!(((u8, u16), (u32, u16, u8)), 1.2);
204204
LL | | offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0);
205-
LL | |
206205
... |
207206
|
208207
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)