Update message for skipped enum variant

This commit is contained in:
David Tolnay 2016-12-24 12:16:28 -05:00
parent 63def96c66
commit 49e985eb90
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 8 additions and 5 deletions

View File

@ -255,8 +255,11 @@ fn serialize_variant(
let variant_ident = variant.ident.clone();
let variant_name = variant.attrs.name().serialize_name();
let skipped_msg = format!("The enum variant {}::{} cannot be serialized",
type_ident, variant_ident);
let skipped_err = quote! {
Err(_serde::ser::Error::invalid_value("The enum variant was skipped for serialization"))
Err(_serde::ser::Error::invalid_value(#skipped_msg))
};
if variant.attrs.skip_serializing() {

View File

@ -402,17 +402,17 @@ fn test_enum_skipped() {
assert_ser_tokens_error(
&Enum::SkippedUnit,
&[],
Error::InvalidValue("The enum variant was skipped for serialization".to_owned()));
Error::InvalidValue("The enum variant Enum::SkippedUnit cannot be serialized".to_owned()));
assert_ser_tokens_error(
&Enum::SkippedOne(42),
&[],
Error::InvalidValue("The enum variant was skipped for serialization".to_owned()));
Error::InvalidValue("The enum variant Enum::SkippedOne cannot be serialized".to_owned()));
assert_ser_tokens_error(
&Enum::SkippedSeq(1, 2),
&[],
Error::InvalidValue("The enum variant was skipped for serialization".to_owned()));
Error::InvalidValue("The enum variant Enum::SkippedSeq cannot be serialized".to_owned()));
assert_ser_tokens_error(
&Enum::SkippedMap { _a: 1, _b: 2 },
&[],
Error::InvalidValue("The enum variant was skipped for serialization".to_owned()));
Error::InvalidValue("The enum variant Enum::SkippedMap cannot be serialized".to_owned()));
}