From def0c5b54a409536fc64e83bdf852e82ea4fb9a1 Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Thu, 10 Aug 2023 18:04:29 -0400 Subject: [PATCH] Avoid field name collisions with the map ident --- pbjson-build/src/generator/message.rs | 42 +++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pbjson-build/src/generator/message.rs b/pbjson-build/src/generator/message.rs index b18929f..4834010 100644 --- a/pbjson-build/src/generator/message.rs +++ b/pbjson-build/src/generator/message.rs @@ -523,7 +523,7 @@ fn write_deserialize_message( {indent} formatter.write_str("struct {name}") {indent} }} -{indent} fn visit_map(self, mut map: V) -> std::result::Result<{rust_type}, V::Error> +{indent} fn visit_map(self, mut map_: V) -> std::result::Result<{rust_type}, V::Error> {indent} where {indent} V: serde::de::MapAccess<'de>, {indent} {{"#, @@ -553,7 +553,7 @@ fn write_deserialize_message( if !message.fields.is_empty() || !message.one_ofs.is_empty() { writeln!( writer, - "{}while let Some(k) = map.next_key()? {{", + "{}while let Some(k) = map_.next_key()? {{", Indent(indent + 2) )?; @@ -588,7 +588,7 @@ fn write_deserialize_message( )?; writeln!( writer, - "{}let _ = map.next_value::()?;", + "{}let _ = map_.next_value::()?;", Indent(indent + 5), )?; writeln!(writer, "{}}}", Indent(indent + 4))?; @@ -599,12 +599,12 @@ fn write_deserialize_message( } else { writeln!( writer, - "{}while map.next_key::()?.is_some() {{", + "{}while map_.next_key::()?.is_some() {{", Indent(indent + 2) )?; writeln!( writer, - "{}let _ = map.next_value::()?;", + "{}let _ = map_.next_value::()?;", Indent(indent + 3) )?; writeln!(writer, "{}}}", Indent(indent + 2))?; @@ -848,7 +848,7 @@ fn write_deserialize_field( Some(deserializer) => { write!( writer, - "map.next_value::<::std::option::Option<{}>>()?.map(|x| {}::{}(x.0))", + "map_.next_value::<::std::option::Option<{}>>()?.map(|x| {}::{}(x.0))", deserializer, resolver.rust_type(&one_of.path), field.rust_type_name() @@ -857,7 +857,7 @@ fn write_deserialize_field( None => { write!( writer, - "map.next_value::<::std::option::Option<_>>()?.map({}::{})", + "map_.next_value::<::std::option::Option<_>>()?.map({}::{})", resolver.rust_type(&one_of.path), field.rust_type_name() )?; @@ -866,7 +866,7 @@ fn write_deserialize_field( FieldType::Enum(path) => { write!( writer, - "map.next_value::<::std::option::Option<{}>>()?.map(|x| {}::{}(x as i32))", + "map_.next_value::<::std::option::Option<{}>>()?.map(|x| {}::{}(x as i32))", resolver.rust_type(path), resolver.rust_type(&one_of.path), field.rust_type_name() @@ -874,7 +874,7 @@ fn write_deserialize_field( } FieldType::Message(_) => writeln!( writer, - "map.next_value::<::std::option::Option<_>>()?.map({}::{})", + "map_.next_value::<::std::option::Option<_>>()?.map({}::{})", resolver.rust_type(&one_of.path), field.rust_type_name() )?, @@ -889,21 +889,21 @@ fn write_deserialize_field( FieldModifier::Optional => { write!( writer, - "map.next_value::<::std::option::Option<{}>>()?.map(|x| x as i32)", + "map_.next_value::<::std::option::Option<{}>>()?.map(|x| x as i32)", resolver.rust_type(path) )?; } FieldModifier::Repeated => { write!( writer, - "Some(map.next_value::>()?.into_iter().map(|x| x as i32).collect())", + "Some(map_.next_value::>()?.into_iter().map(|x| x as i32).collect())", resolver.rust_type(path) )?; } _ => { write!( writer, - "Some(map.next_value::<{}>()? as i32)", + "Some(map_.next_value::<{}>()? as i32)", resolver.rust_type(path) )?; } @@ -914,12 +914,12 @@ fn write_deserialize_field( match btree_map { true => write!( writer, - "{}map.next_value:: write!( writer, - "{}map.next_value::( FieldType::Message(_) => match field.field_modifier { FieldModifier::Repeated => { // No explicit presence for repeated fields - write!(writer, "Some(map.next_value()?)")?; + write!(writer, "Some(map_.next_value()?)")?; } - _ => write!(writer, "map.next_value()?")?, + _ => write!(writer, "map_.next_value()?")?, }, }, } @@ -1010,9 +1010,9 @@ fn write_encode_scalar_field( None => { return match field_modifier { FieldModifier::Optional => { - write!(writer, "map.next_value()?") + write!(writer, "map_.next_value()?") } - _ => write!(writer, "Some(map.next_value()?)"), + _ => write!(writer, "Some(map_.next_value()?)"), }; } }; @@ -1023,7 +1023,7 @@ fn write_encode_scalar_field( FieldModifier::Optional => { writeln!( writer, - "{}map.next_value::<::std::option::Option<{}>>()?.map(|x| x.0)", + "{}map_.next_value::<::std::option::Option<{}>>()?.map(|x| x.0)", Indent(indent + 1), deserializer )?; @@ -1031,7 +1031,7 @@ fn write_encode_scalar_field( FieldModifier::Repeated => { writeln!( writer, - "{}Some(map.next_value::>()?", + "{}Some(map_.next_value::>()?", Indent(indent + 1), deserializer )?; @@ -1044,7 +1044,7 @@ fn write_encode_scalar_field( _ => { writeln!( writer, - "{}Some(map.next_value::<{}>()?.0)", + "{}Some(map_.next_value::<{}>()?.0)", Indent(indent + 1), deserializer )?;