Skip to content

Commit

Permalink
Rollup merge of rust-lang#97798 - WaffleLapkin:allow_for_suggestions_…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Dylan-DPC authored Jun 17, 2022
2 parents f8f9d01 + 4d88993 commit 51e2d6a
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 21 deletions.
18 changes: 18 additions & 0 deletions tests/ui/bind_instead_of_map_multipart.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,25 @@ LL | if s == "43" {
LL ~ return 43;
LL | }
LL | s == "42"
LL | } {
LL ~ return 45;
LL | }
LL | match s.len() {
LL ~ 10 => 2,
LL | 20 => {
...
LL | if foo() {
LL ~ return 20;
LL | }
LL | println!("foo");
LL ~ 3
LL | };
LL | }
LL ~ 20
LL | },
LL ~ 40 => 30,
LL ~ _ => 1,
|

error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`
--> $DIR/bind_instead_of_map_multipart.rs:61:13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ LL + id: e_id,
LL + name: "Player 1".to_string(),
LL + some_data: vec![0x12, 0x34, 0x56, 0x78, 0x90],
LL + };
...
LL + process_data(pack);
|

error: all if blocks contain the same code at both the start and the end
--> $DIR/shared_at_top_and_bottom.rs:94:5
Expand Down
41 changes: 35 additions & 6 deletions tests/ui/entry.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ LL + v
LL + } else {
LL + v2
LL + }
...
LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:38:5
Expand All @@ -50,7 +51,8 @@ LL + v
LL + } else {
LL + v2
LL + }
...
LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:47:5
Expand All @@ -72,7 +74,9 @@ LL + e.insert(v);
LL + } else {
LL + e.insert(v2);
LL + return;
...
LL + }
LL + }
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:57:5
Expand Down Expand Up @@ -111,7 +115,11 @@ LL + 1 if true => {
LL + v
LL + },
LL + _ => {
...
LL + v2
LL + },
LL + }
LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:75:5
Expand All @@ -133,7 +141,9 @@ LL + 0 => foo(),
LL + _ => {
LL + e.insert(v2);
LL + },
...
LL + };
LL + }
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:85:5
Expand All @@ -155,7 +165,26 @@ LL + match 0 {
LL + 0 if false => {
LL + v
LL + },
...
LL + 1 => {
LL + foo();
LL + v
LL + },
LL + 2 | 3 => {
LL + for _ in 0..2 {
LL + foo();
LL + }
LL + if true {
LL + v
LL + } else {
LL + v2
LL + }
LL + },
LL + _ => {
LL + v2
LL + },
LL + }
LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:119:5
Expand Down
17 changes: 13 additions & 4 deletions tests/ui/entry_with_else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ LL + e.insert(v);
LL + }
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
LL + e.insert(v2);
...
LL + }
LL + }
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry_with_else.rs:22:5
Expand All @@ -37,7 +39,9 @@ LL + e.insert(v);
LL + }
LL + std::collections::hash_map::Entry::Vacant(e) => {
LL + e.insert(v2);
...
LL + }
LL + }
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry_with_else.rs:28:5
Expand Down Expand Up @@ -95,7 +99,9 @@ LL + e.insert(v);
LL + }
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
LL + e.insert(v2);
...
LL + }
LL + }
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry_with_else.rs:46:5
Expand All @@ -115,7 +121,10 @@ LL + if true { Some(e.insert(v)) } else { Some(e.insert(v2)) }
LL + }
LL + std::collections::hash_map::Entry::Vacant(e) => {
LL + e.insert(v);
...
LL + None
LL + }
LL ~ };
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry_with_else.rs:52:5
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/let_unit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ LL + .map(|i| i * 2)
LL + .filter(|i| i % 2 == 0)
LL + .map(|_| ())
LL + .next()
...
LL + .unwrap();
|

error: this let-binding has unit value
--> $DIR/let_unit.rs:80:5
Expand Down
9 changes: 8 additions & 1 deletion tests/ui/manual_async_fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,14 @@ LL + let a = 42;
LL + let b = 21;
LL + if a < b {
LL + let c = 21;
...
LL + let d = 42;
LL + if c < d {
LL + let _ = 42;
LL + }
LL + }
LL + 42
LL + }
|

error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:92:1
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/needless_for_each_unfixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ LL + return;
LL + } else {
LL + println!("{}", v);
LL + }
...
LL + }
|
help: ...and replace `return` with `continue`
|
LL | continue;
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/new_without_default.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ LL + Self::new()
LL + }
LL + }
LL +
...
LL ~ impl<T> Foo<T> {
|

error: aborting due to 7 previous errors

3 changes: 2 additions & 1 deletion tests/ui/ptr_arg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ LL | let f = e.clone(); // OK
LL | let g = x;
LL ~ let h = g.to_owned();
LL | let i = (e).clone();
...
LL ~ x.to_owned()
|

error: writing `&String` instead of `&str` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:57:18
Expand Down
9 changes: 7 additions & 2 deletions tests/ui/significant_drop_in_scrutinee.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ LL + _ => mutex2.lock().unwrap(),
LL + }
LL + .s
LL + .len()
...
LL + > 1;
LL ~ match value
|

error: temporary with significant drop in match scrutinee
--> $DIR/significant_drop_in_scrutinee.rs:397:11
Expand All @@ -211,7 +213,10 @@ LL + } else {
LL + mutex2.lock().unwrap()
LL + }
LL + .s
...
LL + .len()
LL + > 1;
LL ~ match value
|

error: temporary with significant drop in match scrutinee
--> $DIR/significant_drop_in_scrutinee.rs:451:11
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/unit_arg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ LL + foo(1);
LL + };
LL + {
LL + foo(2);
...
LL + foo(3);
LL + };
LL + taking_multiple_units(
LL + (),
LL + (),
LL ~ );
|

error: passing a unit value to a function
--> $DIR/unit_arg.rs:85:13
Expand Down
6 changes: 4 additions & 2 deletions tests/ui/unnecessary_wraps.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ LL | if a {
LL | Some(-1);
LL ~ 2
LL | } else {
...
LL ~ return 1337;
|

error: this function's return value is unnecessarily wrapped by `Option`
--> $DIR/unnecessary_wraps.rs:21:1
Expand Down Expand Up @@ -122,7 +123,8 @@ LL | if a {
LL | Some(());
LL ~
LL | } else {
...
LL ~ return ;
|

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

0 comments on commit 51e2d6a

Please sign in to comment.