Repository: rust
Issue: Producing better output in case of "error[E0277]: the size for values of type `dyn std::error::Error` cannot be known at compilation time"
Labels: A-diagnostics,T-compiler

Given the following code: ([Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=16bc3de98bdd8816f23b0863cf5fa85e))

```rust
// credits to kpreid in the official Discord server
use std::error::Error;

fn wants_an_error(e: impl Into<Box<dyn Error + Send + Sync>>) {}

fn main() {
    let x: Box<dyn Error> = Box::new("oops".parse::<i32>().unwrap_err());
    wants_an_error(x);
}
```

The current output is:

```
error[E0277]: the size for values of type `dyn std::error::Error` cannot be known at compilation time
 --> src\main.rs:7:20
  |
7 |     wants_an_error(x);
  |     -------------- ^ doesn't have a size known at compile-time
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `Sized` is not implemented for `dyn std::error::Error`
  = note: required because of the requirements on the impl of `std::error::Error` for `Box<dyn std::error::Error>`
  = note: required because of the requirements on the impl of `From<Box<dyn std::error::Error>>` for `Box<(dyn std::error::Error + Send + Sync + 'static)>`
  = note: required because of the requirements on the impl of `Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>` for `Box<dyn std::error::Error>`
note: required by a bound in `wants_an_error`
 --> src\main.rs:3:27
  |
3 | fn wants_an_error(e: impl Into<Box<dyn Error + Send + Sync>>) {}
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `wants_an_error`

error[E0277]: `dyn std::error::Error` cannot be sent between threads safely
 --> src\main.rs:7:20
  |
7 |     wants_an_error(x);
  |     -------------- ^ `dyn std::error::Error` cannot be sent between threads safely
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `Send` is not implemented for `dyn std::error::Error`
  = note: required because of the requirements on the impl of `Send` for `Unique<dyn std::error::Error>`
  = note: required because it appears within the type `Box<dyn std::error::Error>`
  = note: required because of the requirements on the impl of `From<Box<dyn std::error::Error>>` for `Box<(dyn std::error::Error + Send + Sync + 'static)>`
  = note: required because of the requirements on the impl of `Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>` for `Box<dyn std::error::Error>`
note: required by a bound in `wants_an_error`
 --> src\main.rs:3:27
  |
3 | fn wants_an_error(e: impl Into<Box<dyn Error + Send + Sync>>) {}
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `wants_an_error`

error[E0277]: `dyn std::error::Error` cannot be shared between threads safely
 --> src\main.rs:7:20
  |
7 |     wants_an_error(x);
  |     -------------- ^ `dyn std::error::Error` cannot be shared between threads safely
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `Sync` is not implemented for `dyn std::error::Error`
  = note: required because of the requirements on the impl of `Sync` for `Unique<dyn std::error::Error>`
  = note: required because it appears within the type `Box<dyn std::error::Error>`
  = note: required because of the requirements on the impl of `From<Box<dyn std::error::Error>>` for `Box<(dyn std::error::Error + Send + Sync + 'static)>`
  = note: required because of the requirements on the impl of `Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>` for `Box<dyn std::error::Error>`
note: required by a bound in `wants_an_error`
 --> src\main.rs:3:27
  |
3 | fn wants_an_error(e: impl Into<Box<dyn Error + Send + Sync>>) {}
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `wants_an_error`

For more information about this error, try `rustc --explain E0277`.
```

I think the output should point more clearly to the solution, which is to declare `x` as `Box<dyn Error + Send + Sync>`. Now that I know what's going on I understand why the compiler complains like that , but in my code it was less obvious and I had no idea until user kpreid in the Discord server explained it to me. The compiler already points to Send and Sync being absent (although maybe in a somewhat obscure way), but the part about Sized confused me and made it more difficult to look for a solution.

The same output is produced by Stable, Beta, and Nightly on the 2021 Edition.