-
-
Notifications
You must be signed in to change notification settings - Fork 857
Open
Description
Given the following code:
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[serde(rename = "Renamed")]
struct Original {
bar: String,
baz: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
serde_json::from_str::<Original>("\"Bar\"").unwrap();
}
}
The test fail with the following error:
Error("invalid type: string \"Bar\", expected struct Original", line: 1, column: 5)
I would expect the following:
Error("invalid type: string \"Bar\", expected struct Renamed", line: 1, column: 5)
Running cargo expand
, I see that the rename macro has some effects:
_serde::Deserializer::deserialize_struct(
__deserializer,
"Renamed",
FIELDS,
__Visitor {
marker: _serde::__private::PhantomData::<Original>,
lifetime: _serde::__private::PhantomData,
},
)
but I also see
fn expecting(
&self,
__formatter: &mut _serde::__private::Formatter,
) -> _serde::__private::fmt::Result {
_serde::__private::Formatter::write_str(
__formatter,
"struct Original",
)
}
So it seems it is the source of the issue.
outscale-fba and m4r1vs
Metadata
Metadata
Assignees
Labels
No labels