Make enum decoding errors more informative.

By printing the actual value, as long as the expected range. I found
this helpful when I encountered one of these errors.
This commit is contained in:
Nicholas Nethercote 2023-08-17 08:51:52 +10:00
parent 9167eea553
commit 3449304722

View file

@ -59,14 +59,14 @@ fn decodable_body(
})
.collect();
let message = format!(
"invalid enum variant tag while decoding `{}`, expected 0..{}",
"invalid enum variant tag while decoding `{}`, expected 0..{}, actual {{}}",
ty_name,
variants.len()
);
quote! {
match ::rustc_serialize::Decoder::read_usize(__decoder) {
#match_inner
_ => panic!(#message),
n => panic!(#message, n),
}
}
}