Repository: rust
Issue: Manual send implementation with partial captures produce hard to read diagnostics
Labels: A-diagnostics,T-compiler

<!--
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: [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=18a79c890fbd3689b2bcf57b92b50e36)

This does not compile with no features enabled but does with the `foo` feature (which forces capture of the whole object).

```rust
use libc::c_void;

type Callback = extern fn(context: *mut c_void);

struct Context(*mut c_void);
unsafe impl Send for Context {}

pub fn run(callback: Callback, context: *mut c_void) {
    let context = Context(context);

    let callback = move || {
        #[cfg(feature = "foo")]
        // Disjoint caapture
        let _c = &context;
        callback(context.0);
    };

    inner(callback);
}

fn inner<F>(_callback: F) where F: Fn() + Send + 'static {}

fn main() { }

```

The current output is:

```
Compiling playground v0.0.1 (/playground)
error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): `*mut c_void` cannot be sent between threads safely
  --> src/main.rs:18:5
   |
11 |       let callback = move || {
   |  ____________________-
12 | |         #[cfg(feature = "foo")]
13 | |         // Disjoint capture
14 | |         let _c = &context;
15 | |         callback(context.0);
16 | |     };
   | |_____- within this `[closure@src/main.rs:11:20: 16:6]`
17 | 
18 |       inner(callback);
   |       ^^^^^ `*mut c_void` cannot be sent between threads safely
   |
   = help: within `[closure@src/main.rs:11:20: 16:6]`, the trait `Send` is not implemented for `*mut c_void`
   = note: required because it appears within the type `[closure@src/main.rs:11:20: 16:6]`
note: required by a bound in `inner`
  --> src/main.rs:21:43
   |
21 | fn inner<F>(_callback: F) where F: Fn() + Send + 'static {}
   |                                           ^^^^ required by this bound in `inner`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error
```

<!-- The following is not always necessary. -->
Ideally the output should look like:

```
   = help: within `[closure@src/main.rs:11:20: 16:6]`, the trait `Send` is not implemented for `*mut c_void` which was partially captured from context of type `Context`.
   = note: required because it appears within the type `[closure@src/main.rs:11:20: 16:6]`
note: required by a bound in `inner`
help: consider forcing capture of the whole object:
15 +           _ = &context;
```

The help text should be improved to make it clear why there is an issue with a type not implementing `Send` while not sending said type directly.

The only place I know to provide for additional context is [the edition guide](https://doc.rust-lang.org/edition-guide/rust-2021/disjoint-capture-in-closures.html).


This issue only exists in edition 2021 since it introduced partial captures.