Skip to content

Commit 65a54a7

Browse files
committed
Tweak multispan rendering
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.
1 parent 21fe748 commit 65a54a7

File tree

111 files changed

+206
-653
lines changed

Some content is hidden

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

111 files changed

+206
-653
lines changed

compiler/rustc_errors/src/emitter.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3048,11 +3048,15 @@ 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.
30523053
let until = (ann.line_start..middle)
30533054
.rev()
30543055
.filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s)))
3055-
.find(|(_, s)| !s.trim().is_empty())
3056+
.find(|(_, s)| {
3057+
let s = s.trim();
3058+
!["", "{", "}", "(", ")", "[", "]"].contains(&s) && !s.starts_with("//")
3059+
})
30563060
.map(|(line, _)| line)
30573061
.unwrap_or(ann.line_start);
30583062
for line in ann.line_start + 1..until {

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
|

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

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
|

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

-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ LL | } else {
4343
| ____________^
4444
LL | | if y == "world" {
4545
LL | | println!("world")
46-
LL | | }
4746
... |
4847
LL | | }
4948
LL | | }
@@ -66,7 +65,6 @@ LL | } else {
6665
| ____________^
6766
LL | | if let Some(42) = Some(42) {
6867
LL | | println!("world")
69-
LL | | }
7068
... |
7169
LL | | }
7270
LL | | }
@@ -89,7 +87,6 @@ LL | } else {
8987
| ____________^
9088
LL | | if let Some(42) = Some(42) {
9189
LL | | println!("world")
92-
LL | | }
9390
... |
9491
LL | | }
9592
LL | | }
@@ -112,7 +109,6 @@ LL | } else {
112109
| ____________^
113110
LL | | if x == "hello" {
114111
LL | | println!("world")
115-
LL | | }
116112
... |
117113
LL | | }
118114
LL | | }
@@ -135,7 +131,6 @@ LL | } else {
135131
| ____________^
136132
LL | | if let Some(42) = Some(42) {
137133
LL | | println!("world")
138-
LL | | }
139134
... |
140135
LL | | }
141136
LL | | }

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

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ 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
... |
96
LL | |
107
LL | | }
@@ -16,9 +13,6 @@ error: this loop could be written as a `while let` loop
1613
--> tests/ui/crashes/ice-360.rs:5:5
1714
|
1815
LL | / loop {
19-
LL | |
20-
LL | |
21-
LL | |
2216
... |
2317
LL | |
2418
LL | | }

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
|

src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ error: backticks are unbalanced
33
|
44
LL | /// This is a doc comment with `unbalanced_tick marks and several words that
55
| _____^
6-
LL | |
7-
LL | | /// should be `encompassed_by` tick marks because they `contain_underscores`.
8-
LL | | /// Because of the initial `unbalanced_tick` pair, the error message is
6+
... |
97
LL | | /// very `confusing_and_misleading`.
108
| |____________________________________^
119
|

src/tools/clippy/tests/ui/empty_line_after/doc_comments.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ error: empty lines after doc comment
9696
--> tests/ui/empty_line_after/doc_comments.rs:63:5
9797
|
9898
LL | / /// for OldA
99-
LL | | // struct OldA;
100-
LL | |
101-
LL | | /// Docs
102-
LL | | /// for OldB
99+
... |
103100
LL | | // struct OldB;
104101
LL | |
105102
| |_^

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() {}

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

-2
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,7 +44,6 @@ error: all variants have the same prefix: `Food`
4544
LL | / enum Food {
4645
LL | |
4746
LL | | FoodGood,
48-
LL | |
4947
... |
5048
LL | |
5149
LL | | }

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

+2-5
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,8 +36,7 @@ error: infinite loop detected
3736
LL | / loop {
3837
LL | |
3938
LL | | loop {
40-
LL | |
41-
LL | | do_something();
39+
... |
4240
LL | | }
4341
LL | | }
4442
| |_________^
@@ -79,8 +77,7 @@ error: infinite loop detected
7977
LL | / loop {
8078
LL | | fn inner_fn() -> ! {
8179
LL | | std::process::exit(0);
82-
LL | | }
83-
LL | | do_something();
80+
... |
8481
LL | | }
8582
| |_____^
8683
|

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

+12-24
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ error: manual implementation of `Iterator::find`
44
LL | / for &v in ARRAY {
55
LL | | if v == n {
66
LL | | return Some(v);
7-
LL | | }
8-
LL | | }
7+
... |
98
LL | | None
109
| |________^ help: replace with an iterator: `ARRAY.iter().find(|&&v| v == n).copied()`
1110
|
@@ -18,8 +17,7 @@ error: manual implementation of `Iterator::find`
1817
LL | / for (a, _) in arr {
1918
LL | | if a % 2 == 0 {
2019
LL | | return Some(a);
21-
LL | | }
22-
LL | | }
20+
... |
2321
LL | | None
2422
| |________^ help: replace with an iterator: `arr.into_iter().map(|(a, _)| a).find(|&a| a % 2 == 0)`
2523

@@ -29,8 +27,7 @@ error: manual implementation of `Iterator::find`
2927
LL | / for el in arr {
3028
LL | | if el.name.len() == 10 {
3129
LL | | return Some(el);
32-
LL | | }
33-
LL | | }
30+
... |
3431
LL | | None
3532
| |________^ help: replace with an iterator: `arr.into_iter().find(|el| el.name.len() == 10)`
3633
|
@@ -42,8 +39,7 @@ error: manual implementation of `Iterator::find`
4239
LL | / for Tuple(a, _) in arr {
4340
LL | | if a >= 3 {
4441
LL | | return Some(a);
45-
LL | | }
46-
LL | | }
42+
... |
4743
LL | | None
4844
| |________^ help: replace with an iterator: `arr.into_iter().map(|Tuple(a, _)| a).find(|&a| a >= 3)`
4945

@@ -53,8 +49,7 @@ error: manual implementation of `Iterator::find`
5349
LL | / for el in arr {
5450
LL | | if el.should_keep() {
5551
LL | | return Some(el);
56-
LL | | }
57-
LL | | }
52+
... |
5853
LL | | None
5954
| |________^ help: replace with an iterator: `arr.into_iter().find(|el| el.should_keep())`
6055
|
@@ -66,8 +61,7 @@ error: manual implementation of `Iterator::find`
6661
LL | / for el in arr {
6762
LL | | if f(el) == 20 {
6863
LL | | return Some(el);
69-
LL | | }
70-
LL | | }
64+
... |
7165
LL | | None
7266
| |________^ help: replace with an iterator: `arr.into_iter().find(|&el| f(el) == 20)`
7367

@@ -77,8 +71,7 @@ error: manual implementation of `Iterator::find`
7771
LL | / for &el in arr.values() {
7872
LL | | if f(el) {
7973
LL | | return Some(el);
80-
LL | | }
81-
LL | | }
74+
... |
8275
LL | | None
8376
| |________^ help: replace with an iterator: `arr.values().find(|&&el| f(el)).copied()`
8477

@@ -88,8 +81,7 @@ error: manual implementation of `Iterator::find`
8881
LL | / for el in arr {
8982
LL | | if el.is_true {
9083
LL | | return Some(el);
91-
LL | | }
92-
LL | | }
84+
... |
9385
LL | | None
9486
| |________^ help: replace with an iterator: `arr.into_iter().find(|el| el.is_true)`
9587
|
@@ -101,8 +93,7 @@ error: manual implementation of `Iterator::find`
10193
LL | / for (_, &x) in v {
10294
LL | | if x > 10 {
10395
LL | | return Some(x);
104-
LL | | }
105-
LL | | }
96+
... |
10697
LL | | None
10798
| |________^ help: replace with an iterator: `v.into_iter().map(|(_, &x)| x).find(|&x| x > 10)`
10899

@@ -112,8 +103,7 @@ error: manual implementation of `Iterator::find`
112103
LL | / for &(_, &x) in v {
113104
LL | | if x > 10 {
114105
LL | | return Some(x);
115-
LL | | }
116-
LL | | }
106+
... |
117107
LL | | None
118108
| |________^ help: replace with an iterator: `v.iter().map(|&(_, &x)| x).find(|&x| x > 10)`
119109

@@ -123,8 +113,7 @@ error: manual implementation of `Iterator::find`
123113
LL | / for x in arr {
124114
LL | | if x >= 5 {
125115
LL | | return Some(x);
126-
LL | | }
127-
LL | | }
116+
... |
128117
LL | | return None;
129118
| |________________^ help: replace with an iterator: `arr.into_iter().find(|&x| x >= 5)`
130119

@@ -134,8 +123,7 @@ error: manual implementation of `Iterator::find`
134123
LL | / for x in arr {
135124
LL | | if x < 1 {
136125
LL | | return Some(x);
137-
LL | | }
138-
LL | | }
126+
... |
139127
LL | | None
140128
| |____________^ help: replace with an iterator: `arr.into_iter().find(|&x| x < 1)`
141129

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

-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ error: called `map(..).flatten()` on `Option`
7777
|
7878
LL | .map(|_| {
7979
| __________^
80-
LL | | // we need some newlines
81-
LL | | // so that the span is big enough
82-
LL | | // for a split output of the diagnostic
8380
... |
8481
LL | | })
8582
LL | | .flatten();

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

-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ error: you seem to be trying to match on a boolean expression
7575
--> tests/ui/match_bool.rs:36:5
7676
|
7777
LL | / match test && test {
78-
LL | |
79-
LL | |
80-
LL | |
8178
... |
8279
LL | | _ => (),
8380
LL | | };

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ LL | let _ans = match x {
6868
| ____________________^
6969
LL | | E::A(_) => {
7070
LL | | true
71-
LL | | }
72-
LL | | E::B(_) => true,
71+
... |
7372
LL | | _ => false,
7473
LL | | };
7574
| |_________^ help: try: `matches!(x, E::A(_) | E::B(_))`

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error: missing documentation for the crate
22
--> tests/ui/missing_doc_crate_missing.rs:1:1
33
|
44
LL | / #![warn(clippy::missing_docs_in_private_items)]
5-
LL | |
6-
LL | |
7-
LL | |
5+
... |
86
LL | | fn main() {}
97
| |____________^
108
|

0 commit comments

Comments
 (0)