Skip to content

Commit 2846699

Browse files
authored
Rollup merge of #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 4a204be + 9f1044e commit 2846699

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

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

+12-3
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 {

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

-2
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

Diff for: src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr

+1-2
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
|

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

-1
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
|

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

-1
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
|

Diff for: src/tools/clippy/tests/ui/async_yields_async.stderr

-1
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
| | ^^^^^^^^^^^^^^^^

Diff for: src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr

-1
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
|

Diff for: src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr

+2-4
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
|

Diff for: src/tools/clippy/tests/ui/collapsible_else_if.stderr

-10
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
|

Diff for: src/tools/clippy/tests/ui/copy_iterator.stderr

-1
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
|

Diff for: src/tools/clippy/tests/ui/crashes/ice-360.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ error: this loop never actually loops
22
--> tests/ui/crashes/ice-360.rs:5:5
33
|
44
LL | / loop {
5-
LL | |
6-
LL | |
7-
LL | |
85
... |
9-
LL | |
106
LL | | }
117
| |_____^
128
|
@@ -16,11 +12,7 @@ error: this loop could be written as a `while let` loop
1612
--> tests/ui/crashes/ice-360.rs:5:5
1713
|
1814
LL | / loop {
19-
LL | |
20-
LL | |
21-
LL | |
2215
... |
23-
LL | |
2416
LL | | }
2517
| |_____^ help: try: `while let Some(ele) = iter.next() { .. }`
2618
|

Diff for: src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ error: this looks like you are trying to swap `a` and `b`
22
--> tests/ui/crate_level_checks/no_std_swap.rs:12:5
33
|
44
LL | / a = b;
5-
LL | |
6-
LL | |
5+
... |
76
LL | | b = a;
87
| |_________^ help: try: `core::mem::swap(&mut a, &mut b)`
98
|

Diff for: src/tools/clippy/tests/ui/derivable_impls.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | | fn default() -> Self {
66
LL | | Self {
77
LL | | a: false,
88
... |
9-
LL | | }
109
LL | | }
1110
| |_^
1211
|

Diff for: src/tools/clippy/tests/ui/empty_line_after/doc_comments.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ LL | / /// for OldA
9999
LL | | // struct OldA;
100100
LL | |
101101
LL | | /// Docs
102-
LL | | /// for OldB
103-
LL | | // struct OldB;
102+
... |
104103
LL | |
105104
| |_^
106105
...

Diff for: src/tools/clippy/tests/ui/empty_line_after/outer_attribute.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ error: empty lines after outer attribute
103103
--> tests/ui/empty_line_after/outer_attribute.rs:64:1
104104
|
105105
LL | / #[allow(unused)]
106-
LL | |
107-
LL | | // This comment is isolated
106+
... |
108107
LL | |
109108
| |_^
110109
LL | pub fn isolated_comment() {}

Diff for: src/tools/clippy/tests/ui/entry.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ LL | / if !m.contains_key(&k) {
1616
LL | | if true {
1717
LL | | m.insert(k, v);
1818
LL | | } else {
19-
LL | | m.insert(k, v2);
20-
LL | | }
19+
... |
2120
LL | | }
2221
| |_____^
2322
|
@@ -63,7 +62,6 @@ LL | | if true {
6362
LL | | m.insert(k, v);
6463
LL | | } else {
6564
... |
66-
LL | | }
6765
LL | | }
6866
| |_____^
6967
|
@@ -154,7 +152,6 @@ LL | | foo();
154152
LL | | match 0 {
155153
LL | | 0 if false => {
156154
... |
157-
LL | | }
158155
LL | | }
159156
| |_____^
160157
|

Diff for: src/tools/clippy/tests/ui/enum_variants.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ error: all variants have the same prefix: `c`
1313
LL | / enum Foo {
1414
LL | |
1515
LL | | cFoo,
16-
LL | |
1716
... |
1817
LL | | cBaz,
1918
LL | | }
@@ -45,9 +44,7 @@ error: all variants have the same prefix: `Food`
4544
LL | / enum Food {
4645
LL | |
4746
LL | | FoodGood,
48-
LL | |
4947
... |
50-
LL | |
5148
LL | | }
5249
| |_^
5350
|

Diff for: src/tools/clippy/tests/ui/fallible_impl_from.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ LL | |
2929
LL | | fn from(i: usize) -> Invalid {
3030
LL | | if i != 42 {
3131
... |
32-
LL | | }
3332
LL | | }
3433
| |_^
3534
|
@@ -49,7 +48,6 @@ LL | |
4948
LL | | fn from(s: Option<String>) -> Invalid {
5049
LL | | let s = s.unwrap();
5150
... |
52-
LL | | }
5351
LL | | }
5452
| |_^
5553
|
@@ -76,7 +74,6 @@ LL | |
7674
LL | | fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
7775
LL | | if s.parse::<u32>().ok().unwrap() != 42 {
7876
... |
79-
LL | | }
8077
LL | | }
8178
| |_^
8279
|

Diff for: src/tools/clippy/tests/ui/if_same_then_else2.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | | for _ in &[42] {
77
LL | | let foo: &Option<_> = &Some::<u8>(42);
88
LL | | if foo.is_some() {
99
... |
10-
LL | | }
1110
LL | | } else {
1211
| |_____^
1312
|
@@ -20,7 +19,6 @@ LL | | for _ in &[42] {
2019
LL | | let bar: &Option<_> = &Some::<u8>(42);
2120
LL | | if bar.is_some() {
2221
... |
23-
LL | | }
2422
LL | | }
2523
| |_____^
2624
= note: `-D clippy::if-same-then-else` implied by `-D warnings`

Diff for: src/tools/clippy/tests/ui/infinite_loops.stderr

+2-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ error: infinite loop detected
2020
LL | / loop {
2121
LL | |
2222
LL | | loop {
23-
LL | |
2423
... |
2524
LL | | do_something();
2625
LL | | }
@@ -37,9 +36,7 @@ error: infinite loop detected
3736
LL | / loop {
3837
LL | |
3938
LL | | loop {
40-
LL | |
41-
LL | | do_something();
42-
LL | | }
39+
... |
4340
LL | | }
4441
| |_________^
4542
|
@@ -79,8 +76,7 @@ error: infinite loop detected
7976
LL | / loop {
8077
LL | | fn inner_fn() -> ! {
8178
LL | | std::process::exit(0);
82-
LL | | }
83-
LL | | do_something();
79+
... |
8480
LL | | }
8581
| |_____^
8682
|
@@ -97,7 +93,6 @@ LL | |
9793
LL | | loop {
9894
LL | | if cond {
9995
... |
100-
LL | | }
10196
LL | | }
10297
| |_____^
10398
|
@@ -114,7 +109,6 @@ LL | |
114109
LL | | 'inner: loop {
115110
LL | | loop {
116111
... |
117-
LL | | }
118112
LL | | }
119113
| |_____^
120114
|
@@ -145,7 +139,6 @@ LL | |
145139
LL | | 'inner: loop {
146140
LL | | loop {
147141
... |
148-
LL | | }
149142
LL | | }
150143
| |_________^
151144
|
@@ -162,7 +155,6 @@ LL | |
162155
LL | | match opt {
163156
LL | | Some(v) => {
164157
... |
165-
LL | | }
166158
LL | | }
167159
| |_____^
168160
|
@@ -279,7 +271,6 @@ LL | |
279271
LL | | 'inner: loop {
280272
LL | | loop {
281273
... |
282-
LL | | }
283274
LL | | }
284275
| |_____^
285276
|

0 commit comments

Comments
 (0)