Skip to content

Commit

Permalink
Avoid field name collisions with the map ident
Browse files Browse the repository at this point in the history
  • Loading branch information
sporkmonger committed Aug 11, 2023
1 parent b2f3e64 commit def0c5b
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions pbjson-build/src/generator/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ fn write_deserialize_message<W: Write>(
{indent} formatter.write_str("struct {name}")
{indent} }}
{indent} fn visit_map<V>(self, mut map: V) -> std::result::Result<{rust_type}, V::Error>
{indent} fn visit_map<V>(self, mut map_: V) -> std::result::Result<{rust_type}, V::Error>
{indent} where
{indent} V: serde::de::MapAccess<'de>,
{indent} {{"#,
Expand Down Expand Up @@ -553,7 +553,7 @@ fn write_deserialize_message<W: Write>(
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)
)?;

Expand Down Expand Up @@ -588,7 +588,7 @@ fn write_deserialize_message<W: Write>(
)?;
writeln!(
writer,
"{}let _ = map.next_value::<serde::de::IgnoredAny>()?;",
"{}let _ = map_.next_value::<serde::de::IgnoredAny>()?;",
Indent(indent + 5),
)?;
writeln!(writer, "{}}}", Indent(indent + 4))?;
Expand All @@ -599,12 +599,12 @@ fn write_deserialize_message<W: Write>(
} else {
writeln!(
writer,
"{}while map.next_key::<GeneratedField>()?.is_some() {{",
"{}while map_.next_key::<GeneratedField>()?.is_some() {{",
Indent(indent + 2)
)?;
writeln!(
writer,
"{}let _ = map.next_value::<serde::de::IgnoredAny>()?;",
"{}let _ = map_.next_value::<serde::de::IgnoredAny>()?;",
Indent(indent + 3)
)?;
writeln!(writer, "{}}}", Indent(indent + 2))?;
Expand Down Expand Up @@ -848,7 +848,7 @@ fn write_deserialize_field<W: Write>(
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()
Expand All @@ -857,7 +857,7 @@ fn write_deserialize_field<W: Write>(
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()
)?;
Expand All @@ -866,15 +866,15 @@ fn write_deserialize_field<W: Write>(
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()
)?;
}
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()
)?,
Expand All @@ -889,21 +889,21 @@ fn write_deserialize_field<W: Write>(
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::<Vec<{}>>()?.into_iter().map(|x| x as i32).collect())",
"Some(map_.next_value::<Vec<{}>>()?.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)
)?;
}
Expand All @@ -914,12 +914,12 @@ fn write_deserialize_field<W: Write>(
match btree_map {
true => write!(
writer,
"{}map.next_value::<std::collections::BTreeMap<",
"{}map_.next_value::<std::collections::BTreeMap<",
Indent(indent + 2),
)?,
false => write!(
writer,
"{}map.next_value::<std::collections::HashMap<",
"{}map_.next_value::<std::collections::HashMap<",
Indent(indent + 2),
)?,
}
Expand Down Expand Up @@ -981,9 +981,9 @@ fn write_deserialize_field<W: Write>(
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()?")?,
},
},
}
Expand All @@ -1010,9 +1010,9 @@ fn write_encode_scalar_field<W: Write>(
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()?)"),
};
}
};
Expand All @@ -1023,15 +1023,15 @@ fn write_encode_scalar_field<W: Write>(
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
)?;
}
FieldModifier::Repeated => {
writeln!(
writer,
"{}Some(map.next_value::<Vec<{}>>()?",
"{}Some(map_.next_value::<Vec<{}>>()?",
Indent(indent + 1),
deserializer
)?;
Expand All @@ -1044,7 +1044,7 @@ fn write_encode_scalar_field<W: Write>(
_ => {
writeln!(
writer,
"{}Some(map.next_value::<{}>()?.0)",
"{}Some(map_.next_value::<{}>()?.0)",
Indent(indent + 1),
deserializer
)?;
Expand Down

0 comments on commit def0c5b

Please sign in to comment.