Repository: rust
Issue: Diagnostics: suggest a `for<'a>` bound where possible
Labels: A-diagnostics,A-lifetimes,T-compiler,D-confusing,D-newcomer-roadblock

@estebank requested I submit this [here](https://twitter.com/ekuber/status/1445361832357662727). This is a small-ish repro for a case where the compiler should suggest we use a `for<'_>` lifetime ([HRTB](https://doc.rust-lang.org/nomicon/hrtb.html)), but currently doesn't.

This repro is based on an issue I encountered [here](https://twitter.com/yoshuawuyts/status/1418726825627459589) ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=64c62d99d47bfa15502d358145676fe2)) while working on [heckcheck](https://docs.rs/heckcheck/1.0.2/heckcheck/). The fix for it was contributed by @BoxyUwU  [here](https://twitter.com/yoshuawuyts/status/1418726825627459589).

---

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.

If you cannot produce a minimal reproduction case (something that would work in
isolation), please provide the steps or even link to a repository that causes
the problematic output to occur.
-->

[Given the following code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5b7fa7f3c640c982fb38cd75fc51c1ab): <!-- Please provide a link to play.rust-lang.org -->

```rust
struct HeckCheck(String);

impl HeckCheck {
    pub fn check<'a, A>(&'a mut self)
    where
        A: Arbitrary<'a>,
    {
        for _ in 0..2 {
            fill(&mut self.0);
            A::arbitrary(&mut self.0);
        }
    }
}

fn fill(_: &mut String) {}

pub trait Arbitrary<'a> {
    fn arbitrary(u: &'a mut String);
}
```

The current output is:

```
error[E0499]: cannot borrow `self.0` as mutable more than once at a time
  --> src/lib.rs:9:18
   |
4  |     pub fn check<'a, A>(&'a mut self)
   |                  -- lifetime `'a` defined here
...
9  |             fill(&mut self.0);
   |                  ^^^^^^^^^^^ second mutable borrow occurs here
10 |             A::arbitrary(&mut self.0);
   |             -------------------------
   |             |            |
   |             |            first mutable borrow occurs here
   |             argument requires that `self.0` is borrowed for `'a`

error[E0499]: cannot borrow `self.0` as mutable more than once at a time
  --> src/lib.rs:10:26
   |
4  |     pub fn check<'a, A>(&'a mut self)
   |                  -- lifetime `'a` defined here
...
10 |             A::arbitrary(&mut self.0);
   |             -------------^^^^^^^^^^^-
   |             |            |
   |             |            `self.0` was mutably borrowed here in the previous iteration of the loop
   |             argument requires that `self.0` is borrowed for `'a`
```

<!-- The following is not always necessary. -->
Ideally the output should look like:

```
error[E0499]: cannot borrow `self.0` as mutable more than once at a time
  --> src/lib.rs:14:18
6  |        A: Arbitrary<'a>,
...
9  |             fill(&mut self.0);
   |                  ^^^^^^^^^^^ first mutable borrow occurs here
10 |             A::arbitrary(&mut self.0);
   |                               ^^^^^^ second mutable borrow occurs here
   |
help: consider giving `A` a higher-rank lifetime
   |
6  |        for<'b> A: Arbitrary<'ab>,
   |        +++++++               ~+

```

<!--
If the problem is not self-explanatory, please provide a rationale for the
change.
-->

<!--
If dramatically different output is caused by small changes, consider also
adding them here.

If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions. The output might also be
different depending on the Edition.
-->