Skip to content

Commit 4fcc959

Browse files
authored
Rollup merge of rust-lang#134181 - estebank:trim-render, r=oli-obk
Tweak multispan rendering to reduce output length Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments. We do that check not only on the first 4 lines of the multispan, but now also on the previous to last line as well.
2 parents 3b5b129 + 9f1044e commit 4fcc959

File tree

181 files changed

+216
-859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+216
-859
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,19 +3048,28 @@ impl FileWithAnnotatedLines {
30483048
// working correctly.
30493049
let middle = min(ann.line_start + 4, ann.line_end);
30503050
// We'll show up to 4 lines past the beginning of the multispan start.
3051-
// We will *not* include the tail of lines that are only whitespace.
3051+
// We will *not* include the tail of lines that are only whitespace, a comment or
3052+
// a bare delimiter.
3053+
let filter = |s: &str| {
3054+
let s = s.trim();
3055+
// Consider comments as empty, but don't consider docstrings to be empty.
3056+
!(s.starts_with("//") && !(s.starts_with("///") || s.starts_with("//!")))
3057+
// Consider lines with nothing but whitespace, a single delimiter as empty.
3058+
&& !["", "{", "}", "(", ")", "[", "]"].contains(&s)
3059+
};
30523060
let until = (ann.line_start..middle)
30533061
.rev()
30543062
.filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s)))
3055-
.find(|(_, s)| !s.trim().is_empty())
3063+
.find(|(_, s)| filter(s))
30563064
.map(|(line, _)| line)
30573065
.unwrap_or(ann.line_start);
30583066
for line in ann.line_start + 1..until {
30593067
// Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
30603068
add_annotation_to_file(&mut output, Lrc::clone(&file), line, ann.as_line());
30613069
}
30623070
let line_end = ann.line_end - 1;
3063-
if middle < line_end {
3071+
let end_is_empty = file.get_line(line_end - 1).map_or(false, |s| !filter(&s));
3072+
if middle < line_end && !end_is_empty {
30643073
add_annotation_to_file(&mut output, Lrc::clone(&file), line_end, ann.as_line());
30653074
}
30663075
} else {

src/tools/clippy/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.default.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ LL | | fn clone_self(&self) -> Self {
2020
LL | | Self {
2121
LL | | a: true,
2222
... |
23-
LL | | }
2423
LL | | }
2524
| |_^
2625
|
@@ -32,7 +31,6 @@ LL | | fn default() -> Self {
3231
LL | | Self {
3332
LL | | a: true,
3433
... |
35-
LL | | }
3634
LL | | }
3735
| |_^
3836

src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ error: this block is too nested
6666
LL | if true {
6767
| _________________________^
6868
LL | | if true {
69-
LL | |
70-
LL | | }
69+
... |
7170
LL | | }
7271
| |_________________^
7372
|

src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ LL | | if unsafe { true } {
286286
LL | | todo!();
287287
LL | | } else {
288288
... |
289-
LL | | }
290289
LL | | };
291290
| |______^
292291
|

src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ LL | | if unsafe { true } {
294294
LL | | todo!();
295295
LL | | } else {
296296
... |
297-
LL | | }
298297
LL | | };
299298
| |______^
300299
|

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ error: an async construct yields a type which is itself awaitable
8080
LL | let _m = async || {
8181
| _______________________-
8282
LL | | println!("I'm bored");
83-
LL | | // Some more stuff
8483
... |
8584
LL | | CustomFutureType
8685
| | ^^^^^^^^^^^^^^^^

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ LL | | if {
4444
LL | | if s == "43" {
4545
LL | | return Some(43);
4646
... |
47-
LL | | }
4847
LL | | });
4948
| |______^
5049
|

src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ error: all if blocks contain the same code at the end
115115
--> tests/ui/branches_sharing_code/shared_at_bottom.rs:183:5
116116
|
117117
LL | / x << 2
118-
LL | |
119-
LL | |
118+
... |
120119
LL | | };
121120
| |_____^
122121
|
@@ -131,8 +130,7 @@ error: all if blocks contain the same code at the end
131130
--> tests/ui/branches_sharing_code/shared_at_bottom.rs:192:5
132131
|
133132
LL | / x * 4
134-
LL | |
135-
LL | |
133+
... |
136134
LL | | }
137135
| |_____^
138136
|

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ LL | } else {
4343
| ____________^
4444
LL | | if y == "world" {
4545
LL | | println!("world")
46-
LL | | }
4746
... |
48-
LL | | }
4947
LL | | }
5048
| |_____^
5149
|
@@ -66,9 +64,7 @@ LL | } else {
6664
| ____________^
6765
LL | | if let Some(42) = Some(42) {
6866
LL | | println!("world")
69-
LL | | }
7067
... |
71-
LL | | }
7268
LL | | }
7369
| |_____^
7470
|
@@ -89,9 +85,7 @@ LL | } else {
8985
| ____________^
9086
LL | | if let Some(42) = Some(42) {
9187
LL | | println!("world")
92-
LL | | }
9388
... |
94-
LL | | }
9589
LL | | }
9690
| |_____^
9791
|
@@ -112,9 +106,7 @@ LL | } else {
112106
| ____________^
113107
LL | | if x == "hello" {
114108
LL | | println!("world")
115-
LL | | }
116109
... |
117-
LL | | }
118110
LL | | }
119111
| |_____^
120112
|
@@ -135,9 +127,7 @@ LL | } else {
135127
| ____________^
136128
LL | | if let Some(42) = Some(42) {
137129
LL | | println!("world")
138-
LL | | }
139130
... |
140-
LL | | }
141131
LL | | }
142132
| |_____^
143133
|

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | |
66
LL | |
77
LL | | type Item = u8;
88
... |
9-
LL | | }
109
LL | | }
1110
| |_^
1211
|

0 commit comments

Comments
 (0)