Skip to content

Commit 51e2d6a

Browse files
authored
Rollup merge of rust-lang#97798 - WaffleLapkin:allow_for_suggestions_that_are_quite_far_away_from_each_other, r=estebank
Hide irrelevant lines in suggestions to allow for suggestions that are far from each other to be shown This is an attempt to fix suggestions one part of which is 6 lines or more far from the first. I've noticed "the problem" (of not showing some parts of the suggestion) here: rust-lang#97759 (comment). I'm not sure about the implementation (this big closure is just bad and makes already complicated code even more so), but I want to at least discuss the result. Here is an example of how this changes the output: Before: ```text help: consider enclosing expression in a block | 3 ~ 'l: { match () { () => break 'l, 4 | 5 | 6 | 7 | 8 | ... ``` After: ```text help: consider enclosing expression in a block | 3 ~ 'l: { match () { () => break 'l, 4 | ... 31| 32~ } }; | ``` r? `@estebank` `@rustbot` label +A-diagnostics +A-suggestion-diagnostics
2 parents f8f9d01 + 4d88993 commit 51e2d6a

12 files changed

+102
-21
lines changed

tests/ui/bind_instead_of_map_multipart.stderr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,25 @@ LL | if s == "43" {
5656
LL ~ return 43;
5757
LL | }
5858
LL | s == "42"
59+
LL | } {
60+
LL ~ return 45;
61+
LL | }
62+
LL | match s.len() {
63+
LL ~ 10 => 2,
64+
LL | 20 => {
5965
...
66+
LL | if foo() {
67+
LL ~ return 20;
68+
LL | }
69+
LL | println!("foo");
70+
LL ~ 3
71+
LL | };
72+
LL | }
73+
LL ~ 20
74+
LL | },
75+
LL ~ 40 => 30,
76+
LL ~ _ => 1,
77+
|
6078

6179
error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`
6280
--> $DIR/bind_instead_of_map_multipart.rs:61:13

tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ LL + id: e_id,
9898
LL + name: "Player 1".to_string(),
9999
LL + some_data: vec![0x12, 0x34, 0x56, 0x78, 0x90],
100100
LL + };
101-
...
101+
LL + process_data(pack);
102+
|
102103

103104
error: all if blocks contain the same code at both the start and the end
104105
--> $DIR/shared_at_top_and_bottom.rs:94:5

tests/ui/entry.stderr

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ LL + v
2828
LL + } else {
2929
LL + v2
3030
LL + }
31-
...
31+
LL + });
32+
|
3233

3334
error: usage of `contains_key` followed by `insert` on a `HashMap`
3435
--> $DIR/entry.rs:38:5
@@ -50,7 +51,8 @@ LL + v
5051
LL + } else {
5152
LL + v2
5253
LL + }
53-
...
54+
LL + });
55+
|
5456

5557
error: usage of `contains_key` followed by `insert` on a `HashMap`
5658
--> $DIR/entry.rs:47:5
@@ -72,7 +74,9 @@ LL + e.insert(v);
7274
LL + } else {
7375
LL + e.insert(v2);
7476
LL + return;
75-
...
77+
LL + }
78+
LL + }
79+
|
7680

7781
error: usage of `contains_key` followed by `insert` on a `HashMap`
7882
--> $DIR/entry.rs:57:5
@@ -111,7 +115,11 @@ LL + 1 if true => {
111115
LL + v
112116
LL + },
113117
LL + _ => {
114-
...
118+
LL + v2
119+
LL + },
120+
LL + }
121+
LL + });
122+
|
115123

116124
error: usage of `contains_key` followed by `insert` on a `HashMap`
117125
--> $DIR/entry.rs:75:5
@@ -133,7 +141,9 @@ LL + 0 => foo(),
133141
LL + _ => {
134142
LL + e.insert(v2);
135143
LL + },
136-
...
144+
LL + };
145+
LL + }
146+
|
137147

138148
error: usage of `contains_key` followed by `insert` on a `HashMap`
139149
--> $DIR/entry.rs:85:5
@@ -155,7 +165,26 @@ LL + match 0 {
155165
LL + 0 if false => {
156166
LL + v
157167
LL + },
158-
...
168+
LL + 1 => {
169+
LL + foo();
170+
LL + v
171+
LL + },
172+
LL + 2 | 3 => {
173+
LL + for _ in 0..2 {
174+
LL + foo();
175+
LL + }
176+
LL + if true {
177+
LL + v
178+
LL + } else {
179+
LL + v2
180+
LL + }
181+
LL + },
182+
LL + _ => {
183+
LL + v2
184+
LL + },
185+
LL + }
186+
LL + });
187+
|
159188

160189
error: usage of `contains_key` followed by `insert` on a `HashMap`
161190
--> $DIR/entry.rs:119:5

tests/ui/entry_with_else.stderr

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ LL + e.insert(v);
1717
LL + }
1818
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
1919
LL + e.insert(v2);
20-
...
20+
LL + }
21+
LL + }
22+
|
2123

2224
error: usage of `contains_key` followed by `insert` on a `HashMap`
2325
--> $DIR/entry_with_else.rs:22:5
@@ -37,7 +39,9 @@ LL + e.insert(v);
3739
LL + }
3840
LL + std::collections::hash_map::Entry::Vacant(e) => {
3941
LL + e.insert(v2);
40-
...
42+
LL + }
43+
LL + }
44+
|
4145

4246
error: usage of `contains_key` followed by `insert` on a `HashMap`
4347
--> $DIR/entry_with_else.rs:28:5
@@ -95,7 +99,9 @@ LL + e.insert(v);
9599
LL + }
96100
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
97101
LL + e.insert(v2);
98-
...
102+
LL + }
103+
LL + }
104+
|
99105

100106
error: usage of `contains_key` followed by `insert` on a `HashMap`
101107
--> $DIR/entry_with_else.rs:46:5
@@ -115,7 +121,10 @@ LL + if true { Some(e.insert(v)) } else { Some(e.insert(v2)) }
115121
LL + }
116122
LL + std::collections::hash_map::Entry::Vacant(e) => {
117123
LL + e.insert(v);
118-
...
124+
LL + None
125+
LL + }
126+
LL ~ };
127+
|
119128

120129
error: usage of `contains_key` followed by `insert` on a `HashMap`
121130
--> $DIR/entry_with_else.rs:52:5

tests/ui/let_unit.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ LL + .map(|i| i * 2)
3232
LL + .filter(|i| i % 2 == 0)
3333
LL + .map(|_| ())
3434
LL + .next()
35-
...
35+
LL + .unwrap();
36+
|
3637

3738
error: this let-binding has unit value
3839
--> $DIR/let_unit.rs:80:5

tests/ui/manual_async_fn.stderr

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ LL + let a = 42;
122122
LL + let b = 21;
123123
LL + if a < b {
124124
LL + let c = 21;
125-
...
125+
LL + let d = 42;
126+
LL + if c < d {
127+
LL + let _ = 42;
128+
LL + }
129+
LL + }
130+
LL + 42
131+
LL + }
132+
|
126133

127134
error: this function can be simplified using the `async fn` syntax
128135
--> $DIR/manual_async_fn.rs:92:1

tests/ui/needless_for_each_unfixable.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ LL + return;
1919
LL + } else {
2020
LL + println!("{}", v);
2121
LL + }
22-
...
22+
LL + }
23+
|
2324
help: ...and replace `return` with `continue`
2425
|
2526
LL | continue;

tests/ui/new_without_default.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ LL + Self::new()
117117
LL + }
118118
LL + }
119119
LL +
120-
...
120+
LL ~ impl<T> Foo<T> {
121+
|
121122

122123
error: aborting due to 7 previous errors
123124

tests/ui/ptr_arg.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ LL | let f = e.clone(); // OK
5656
LL | let g = x;
5757
LL ~ let h = g.to_owned();
5858
LL | let i = (e).clone();
59-
...
59+
LL ~ x.to_owned()
60+
|
6061

6162
error: writing `&String` instead of `&str` involves a new object where a slice will do
6263
--> $DIR/ptr_arg.rs:57:18

tests/ui/significant_drop_in_scrutinee.stderr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ LL + _ => mutex2.lock().unwrap(),
188188
LL + }
189189
LL + .s
190190
LL + .len()
191-
...
191+
LL + > 1;
192+
LL ~ match value
193+
|
192194

193195
error: temporary with significant drop in match scrutinee
194196
--> $DIR/significant_drop_in_scrutinee.rs:397:11
@@ -211,7 +213,10 @@ LL + } else {
211213
LL + mutex2.lock().unwrap()
212214
LL + }
213215
LL + .s
214-
...
216+
LL + .len()
217+
LL + > 1;
218+
LL ~ match value
219+
|
215220

216221
error: temporary with significant drop in match scrutinee
217222
--> $DIR/significant_drop_in_scrutinee.rs:451:11

tests/ui/unit_arg.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@ LL + foo(1);
137137
LL + };
138138
LL + {
139139
LL + foo(2);
140-
...
140+
LL + foo(3);
141+
LL + };
142+
LL + taking_multiple_units(
143+
LL + (),
144+
LL + (),
145+
LL ~ );
146+
|
141147

142148
error: passing a unit value to a function
143149
--> $DIR/unit_arg.rs:85:13

tests/ui/unnecessary_wraps.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ LL | if a {
2323
LL | Some(-1);
2424
LL ~ 2
2525
LL | } else {
26-
...
26+
LL ~ return 1337;
27+
|
2728

2829
error: this function's return value is unnecessarily wrapped by `Option`
2930
--> $DIR/unnecessary_wraps.rs:21:1
@@ -122,7 +123,8 @@ LL | if a {
122123
LL | Some(());
123124
LL ~
124125
LL | } else {
125-
...
126+
LL ~ return ;
127+
|
126128

127129
error: this function's return value is unnecessary
128130
--> $DIR/unnecessary_wraps.rs:117:1

0 commit comments

Comments
 (0)