Skip to content

Commit

Permalink
correct some inconsistent match bindings
Browse files Browse the repository at this point in the history
Testing out the Rust 2024 edition revealed some cases where the generated serialization code is inconsistent with its binding modes. We start as ref, switch to move (using deref operator), then back to ref (using ref). The 2024 edition doesn't let you do this, and we don't need to anyway (just stay in ref mode), so let's fix that.
  • Loading branch information
wfraser committed Feb 21, 2025
1 parent ac6b94e commit 0ed284c
Show file tree
Hide file tree
Showing 19 changed files with 1,823 additions and 1,823 deletions.
12 changes: 6 additions & 6 deletions generator/rust.stoneg.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,10 @@ def _impl_serde_for_polymorphic_struct(self, struct: ir.Struct) -> None:
with self._impl_serialize(type_name):
self.emit('// polymorphic struct serializer')
self.emit('use serde::ser::SerializeStruct;')
with self.block('match *self'):
with self.block('match self'):
for subtype in struct.get_enumerated_subtypes():
variant_name = self.enum_variant_name(subtype)
with self.block(f'{type_name}::{variant_name}(ref x) =>'):
with self.block(f'{type_name}::{variant_name}(x) =>'):
self.emit('let mut s = serializer.serialize_struct('
f'"{type_name}", {len(subtype.data_type.all_fields) + 1})?;')
self.emit(f's.serialize_field(".tag", "{subtype.name}")?;')
Expand Down Expand Up @@ -710,7 +710,7 @@ def _impl_serde_for_union(self, union: ir.Union) -> None:
'no defined variants"))')
else:
self.emit('use serde::ser::SerializeStruct;')
with self.block('match *self'):
with self.block('match self'):
for field in union.all_fields:
if field.catch_all:
# Handle the 'Other' variant at the end.
Expand All @@ -726,8 +726,8 @@ def _impl_serde_for_union(self, union: ir.Union) -> None:
ultimate_type = ir.unwrap(field.data_type)[0]
needs_x = not (isinstance(field.data_type, ir.Struct)
and not field.data_type.all_fields)
ref_x = 'ref x' if needs_x else '_'
with self.block(f'{type_name}::{variant_name}({ref_x}) =>'):
inner = 'x' if needs_x else '_'
with self.block(f'{type_name}::{variant_name}({inner}) =>'):
if self.is_enum_type(ultimate_type):
# Inner type is a union or polymorphic struct; need to always
# emit another nesting level.
Expand All @@ -746,7 +746,7 @@ def _impl_serde_for_union(self, union: ir.Union) -> None:
self.emit(f'let n = if x.is_some() {{ {num_fields + 1} }} else {{ 1 }};')
self.emit(f'let mut s = serializer.serialize_struct("{union.name}", n)?;')
self.emit(f's.serialize_field(".tag", "{field.name}")?;')
with self.block('if let Some(ref x) = x'):
with self.block('if let Some(x) = x'):
if ir.is_primitive_type(ultimate_type):
self.emit(f's.serialize_field("{field.name}", &x)?;')
else:
Expand Down
6 changes: 3 additions & 3 deletions src/generated/types/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ impl ::serde::ser::Serialize for PhotoSourceArg {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
PhotoSourceArg::Base64Data(ref x) => {
match self {
PhotoSourceArg::Base64Data(x) => {
// primitive
let mut s = serializer.serialize_struct("PhotoSourceArg", 2)?;
s.serialize_field(".tag", "base64_data")?;
Expand Down Expand Up @@ -220,7 +220,7 @@ impl ::serde::ser::Serialize for SetProfilePhotoError {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
SetProfilePhotoError::FileTypeError => {
// unit
let mut s = serializer.serialize_struct("SetProfilePhotoError", 1)?;
Expand Down
18 changes: 9 additions & 9 deletions src/generated/types/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ impl ::serde::ser::Serialize for AccessError {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
AccessError::InvalidAccountType(ref x) => {
match self {
AccessError::InvalidAccountType(x) => {
// union or polymporphic struct
let mut s = serializer.serialize_struct("AccessError", 2)?;
s.serialize_field(".tag", "invalid_account_type")?;
s.serialize_field("invalid_account_type", x)?;
s.end()
}
AccessError::PaperAccessDenied(ref x) => {
AccessError::PaperAccessDenied(x) => {
// union or polymporphic struct
let mut s = serializer.serialize_struct("AccessError", 2)?;
s.serialize_field(".tag", "paper_access_denied")?;
Expand Down Expand Up @@ -176,7 +176,7 @@ impl ::serde::ser::Serialize for AuthError {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
AuthError::InvalidAccessToken => {
// unit
let mut s = serializer.serialize_struct("AuthError", 1)?;
Expand Down Expand Up @@ -207,7 +207,7 @@ impl ::serde::ser::Serialize for AuthError {
s.serialize_field(".tag", "expired_access_token")?;
s.end()
}
AuthError::MissingScope(ref x) => {
AuthError::MissingScope(x) => {
// struct
let mut s = serializer.serialize_struct("AuthError", 2)?;
s.serialize_field(".tag", "missing_scope")?;
Expand Down Expand Up @@ -290,7 +290,7 @@ impl ::serde::ser::Serialize for InvalidAccountTypeError {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
InvalidAccountTypeError::Endpoint => {
// unit
let mut s = serializer.serialize_struct("InvalidAccountTypeError", 1)?;
Expand Down Expand Up @@ -368,7 +368,7 @@ impl ::serde::ser::Serialize for PaperAccessError {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
PaperAccessError::PaperDisabled => {
// unit
let mut s = serializer.serialize_struct("PaperAccessError", 1)?;
Expand Down Expand Up @@ -558,7 +558,7 @@ impl ::serde::ser::Serialize for RateLimitReason {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
RateLimitReason::TooManyRequests => {
// unit
let mut s = serializer.serialize_struct("RateLimitReason", 1)?;
Expand Down Expand Up @@ -737,7 +737,7 @@ impl ::serde::ser::Serialize for TokenFromOAuth1Error {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
TokenFromOAuth1Error::InvalidOauth1TokenInfo => {
// unit
let mut s = serializer.serialize_struct("TokenFromOAuth1Error", 1)?;
Expand Down
16 changes: 8 additions & 8 deletions src/generated/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ impl ::serde::ser::Serialize for PathRoot {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
PathRoot::Home => {
// unit
let mut s = serializer.serialize_struct("PathRoot", 1)?;
s.serialize_field(".tag", "home")?;
s.end()
}
PathRoot::Root(ref x) => {
PathRoot::Root(x) => {
// primitive
let mut s = serializer.serialize_struct("PathRoot", 2)?;
s.serialize_field(".tag", "root")?;
s.serialize_field("root", x)?;
s.end()
}
PathRoot::NamespaceId(ref x) => {
PathRoot::NamespaceId(x) => {
// primitive
let mut s = serializer.serialize_struct("PathRoot", 2)?;
s.serialize_field(".tag", "namespace_id")?;
Expand Down Expand Up @@ -166,8 +166,8 @@ impl ::serde::ser::Serialize for PathRootError {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
PathRootError::InvalidRoot(ref x) => {
match self {
PathRootError::InvalidRoot(x) => {
// union or polymporphic struct
let mut s = serializer.serialize_struct("PathRootError", 2)?;
s.serialize_field(".tag", "invalid_root")?;
Expand Down Expand Up @@ -244,14 +244,14 @@ impl ::serde::ser::Serialize for RootInfo {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// polymorphic struct serializer
use serde::ser::SerializeStruct;
match *self {
RootInfo::Team(ref x) => {
match self {
RootInfo::Team(x) => {
let mut s = serializer.serialize_struct("RootInfo", 4)?;
s.serialize_field(".tag", "team")?;
x.internal_serialize::<S>(&mut s)?;
s.end()
}
RootInfo::User(ref x) => {
RootInfo::User(x) => {
let mut s = serializer.serialize_struct("RootInfo", 3)?;
s.serialize_field(".tag", "user")?;
x.internal_serialize::<S>(&mut s)?;
Expand Down
4 changes: 2 additions & 2 deletions src/generated/types/contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ impl ::serde::ser::Serialize for DeleteManualContactsError {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
DeleteManualContactsError::ContactsNotFound(ref x) => {
match self {
DeleteManualContactsError::ContactsNotFound(x) => {
// primitive
let mut s = serializer.serialize_struct("DeleteManualContactsError", 2)?;
s.serialize_field(".tag", "contacts_not_found")?;
Expand Down
14 changes: 7 additions & 7 deletions src/generated/types/dbx_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl ::serde::ser::Serialize for LaunchEmptyResult {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
LaunchEmptyResult::AsyncJobId(ref x) => {
match self {
LaunchEmptyResult::AsyncJobId(x) => {
// primitive
let mut s = serializer.serialize_struct("LaunchEmptyResult", 2)?;
s.serialize_field(".tag", "async_job_id")?;
Expand Down Expand Up @@ -136,8 +136,8 @@ impl ::serde::ser::Serialize for LaunchResultBase {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
LaunchResultBase::AsyncJobId(ref x) => {
match self {
LaunchResultBase::AsyncJobId(x) => {
// primitive
let mut s = serializer.serialize_struct("LaunchResultBase", 2)?;
s.serialize_field(".tag", "async_job_id")?;
Expand Down Expand Up @@ -285,7 +285,7 @@ impl ::serde::ser::Serialize for PollEmptyResult {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
PollEmptyResult::InProgress => {
// unit
let mut s = serializer.serialize_struct("PollEmptyResult", 1)?;
Expand Down Expand Up @@ -359,7 +359,7 @@ impl ::serde::ser::Serialize for PollError {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
PollError::InvalidAsyncJobId => {
// unit
let mut s = serializer.serialize_struct("PollError", 1)?;
Expand Down Expand Up @@ -431,7 +431,7 @@ impl ::serde::ser::Serialize for PollResultBase {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// union serializer
use serde::ser::SerializeStruct;
match *self {
match self {
PollResultBase::InProgress => {
// unit
let mut s = serializer.serialize_struct("PollResultBase", 1)?;
Expand Down
Loading

0 comments on commit 0ed284c

Please sign in to comment.