I ended up with a weird compiler error message with the following code (see playground).
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 error message that seems dubious 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 `Some`
|
10 | #[derive(Some(Deserialize))]
| +++++ +
Note that the code does have an error since the struct
takes an Option<bool>
but the custom_deserialize
function returns only a bool
. In this case, I'm wondering if this is more a compiler problem? Or a macro problem (on serde
side)?
My goal is to report an issue, but I prefer to not report on the wrong project.