Shorten long SerializeWith type paths in abi digest (#18734)

This commit is contained in:
Justin Starry
2021-07-20 08:59:50 -05:00
committed by GitHub
parent dff9c88193
commit 207c90bd8b
7 changed files with 19 additions and 7 deletions

View File

@@ -49,6 +49,17 @@ impl DigestError {
const INDENT_WIDTH: usize = 4;
pub(crate) fn shorten_serialize_with(type_name: &str) -> &str {
// Fully qualified type names for the generated `__SerializeWith` types are very
// long and do not add extra value to the digest. They also cause the digest
// to change when a struct is moved to an inner module.
if type_name.ends_with("__SerializeWith") {
"__SerializeWith"
} else {
type_name
}
}
impl AbiDigester {
pub fn create() -> Self {
AbiDigester {
@@ -164,7 +175,8 @@ impl AbiDigester {
key: Sstr,
v: &T,
) -> Result<(), DigestError> {
self.update_with_string(format!("field {}: {}", key, type_name::<T>()));
let field_type_name = shorten_serialize_with(type_name::<T>());
self.update_with_string(format!("field {}: {}", key, field_type_name));
self.create_child()?
.digest_data(v)
.map(|_| ())