Repository: rust
Issue: Incorrect compiler's suggestion on a `#[derive(Deserialize)]` on struct with an `Option`'s field and custom `deserialize_with`
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=374993a88f7a4239b241f101a49bfa22)):
```rust
use serde::Deserialize;

pub fn custom_deserialize<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
    D: serde::Deserializer<'de>,
{
    Ok(true)
}

#[derive(Deserialize)]
struct Foo {
    #[serde(deserialize_with = "custom_deserialize")]
    bar: Option<bool>,
}
```

The current output is:

```
error[E0308]: mismatched types
  --> src/lib.rs:10:10
   |
10 | #[derive(Deserialize)]
   |          ^^^^^^^^^^^ expected enum `std::option::Option`, found `bool`
   |
   = note: expected enum `std::option::Option<bool>`
              found type `bool`
   = note: this error originates in the macro `try` (in Nightly builds, run with -Z macro-backtrace for more info)
help: try wrapping the expression in `Option`
   |
10 | #[derive(Some(Deserialize))]
   |          +++++           +
```

<!-- The following is not always necessary. -->
Ideally the output should look like (not sure of my proposition, but at least, the second part needs to change):

```
error[E0308]: mismatched types
  --> src/lib.rs:10:10
   |
10 | #[derive(Deserialize)]
   |          ^^^^^^^^^^^ expected enum `std::option::Option`, found `bool`
   |
   = note: expected enum `std::option::Option<bool>`
              found type `bool`
   = note: this error originates in the macro `try` (in Nightly builds, run with -Z macro-backtrace for more info)
help: try wrapping the expression in `Some`
   |
 3 | pub fn custom_deserialize<'de, D>(deserializer: D) -> Result<Option<bool>, D::Error>
   |                                                              +++++++    +
```

<!--
If the problem is not self-explanatory, please provide a rationale for the
change.
-->
The compiler correctly identifies the code as incorrect, since the function used in `deserialize_with` returns a `bool` instead of an `Option<bool>`. However, the suggestion of the compiler seems off.

Discussion about this diagnostic problem has been started on URLO (see [this thread](https://users.rust-lang.org/t/dubious-compiler-error-when-using-derive-deserialize-on-option-bool-with-incorrect-deserialize-with/87355?u=woshilapin)).
<!--
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.
-->


<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"Ezrashaw"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->