Skip to content

Commit 0ed284c

Browse files
committed
correct some inconsistent match bindings
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.
1 parent ac6b94e commit 0ed284c

19 files changed

+1823
-1823
lines changed

generator/rust.stoneg.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,10 @@ def _impl_serde_for_polymorphic_struct(self, struct: ir.Struct) -> None:
608608
with self._impl_serialize(type_name):
609609
self.emit('// polymorphic struct serializer')
610610
self.emit('use serde::ser::SerializeStruct;')
611-
with self.block('match *self'):
611+
with self.block('match self'):
612612
for subtype in struct.get_enumerated_subtypes():
613613
variant_name = self.enum_variant_name(subtype)
614-
with self.block(f'{type_name}::{variant_name}(ref x) =>'):
614+
with self.block(f'{type_name}::{variant_name}(x) =>'):
615615
self.emit('let mut s = serializer.serialize_struct('
616616
f'"{type_name}", {len(subtype.data_type.all_fields) + 1})?;')
617617
self.emit(f's.serialize_field(".tag", "{subtype.name}")?;')
@@ -710,7 +710,7 @@ def _impl_serde_for_union(self, union: ir.Union) -> None:
710710
'no defined variants"))')
711711
else:
712712
self.emit('use serde::ser::SerializeStruct;')
713-
with self.block('match *self'):
713+
with self.block('match self'):
714714
for field in union.all_fields:
715715
if field.catch_all:
716716
# Handle the 'Other' variant at the end.
@@ -726,8 +726,8 @@ def _impl_serde_for_union(self, union: ir.Union) -> None:
726726
ultimate_type = ir.unwrap(field.data_type)[0]
727727
needs_x = not (isinstance(field.data_type, ir.Struct)
728728
and not field.data_type.all_fields)
729-
ref_x = 'ref x' if needs_x else '_'
730-
with self.block(f'{type_name}::{variant_name}({ref_x}) =>'):
729+
inner = 'x' if needs_x else '_'
730+
with self.block(f'{type_name}::{variant_name}({inner}) =>'):
731731
if self.is_enum_type(ultimate_type):
732732
# Inner type is a union or polymorphic struct; need to always
733733
# emit another nesting level.
@@ -746,7 +746,7 @@ def _impl_serde_for_union(self, union: ir.Union) -> None:
746746
self.emit(f'let n = if x.is_some() {{ {num_fields + 1} }} else {{ 1 }};')
747747
self.emit(f'let mut s = serializer.serialize_struct("{union.name}", n)?;')
748748
self.emit(f's.serialize_field(".tag", "{field.name}")?;')
749-
with self.block('if let Some(ref x) = x'):
749+
with self.block('if let Some(x) = x'):
750750
if ir.is_primitive_type(ultimate_type):
751751
self.emit(f's.serialize_field("{field.name}", &x)?;')
752752
else:

src/generated/types/account.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl ::serde::ser::Serialize for PhotoSourceArg {
5757
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
5858
// union serializer
5959
use serde::ser::SerializeStruct;
60-
match *self {
61-
PhotoSourceArg::Base64Data(ref x) => {
60+
match self {
61+
PhotoSourceArg::Base64Data(x) => {
6262
// primitive
6363
let mut s = serializer.serialize_struct("PhotoSourceArg", 2)?;
6464
s.serialize_field(".tag", "base64_data")?;
@@ -220,7 +220,7 @@ impl ::serde::ser::Serialize for SetProfilePhotoError {
220220
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
221221
// union serializer
222222
use serde::ser::SerializeStruct;
223-
match *self {
223+
match self {
224224
SetProfilePhotoError::FileTypeError => {
225225
// unit
226226
let mut s = serializer.serialize_struct("SetProfilePhotoError", 1)?;

src/generated/types/auth.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ impl ::serde::ser::Serialize for AccessError {
6868
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
6969
// union serializer
7070
use serde::ser::SerializeStruct;
71-
match *self {
72-
AccessError::InvalidAccountType(ref x) => {
71+
match self {
72+
AccessError::InvalidAccountType(x) => {
7373
// union or polymporphic struct
7474
let mut s = serializer.serialize_struct("AccessError", 2)?;
7575
s.serialize_field(".tag", "invalid_account_type")?;
7676
s.serialize_field("invalid_account_type", x)?;
7777
s.end()
7878
}
79-
AccessError::PaperAccessDenied(ref x) => {
79+
AccessError::PaperAccessDenied(x) => {
8080
// union or polymporphic struct
8181
let mut s = serializer.serialize_struct("AccessError", 2)?;
8282
s.serialize_field(".tag", "paper_access_denied")?;
@@ -176,7 +176,7 @@ impl ::serde::ser::Serialize for AuthError {
176176
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
177177
// union serializer
178178
use serde::ser::SerializeStruct;
179-
match *self {
179+
match self {
180180
AuthError::InvalidAccessToken => {
181181
// unit
182182
let mut s = serializer.serialize_struct("AuthError", 1)?;
@@ -207,7 +207,7 @@ impl ::serde::ser::Serialize for AuthError {
207207
s.serialize_field(".tag", "expired_access_token")?;
208208
s.end()
209209
}
210-
AuthError::MissingScope(ref x) => {
210+
AuthError::MissingScope(x) => {
211211
// struct
212212
let mut s = serializer.serialize_struct("AuthError", 2)?;
213213
s.serialize_field(".tag", "missing_scope")?;
@@ -290,7 +290,7 @@ impl ::serde::ser::Serialize for InvalidAccountTypeError {
290290
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
291291
// union serializer
292292
use serde::ser::SerializeStruct;
293-
match *self {
293+
match self {
294294
InvalidAccountTypeError::Endpoint => {
295295
// unit
296296
let mut s = serializer.serialize_struct("InvalidAccountTypeError", 1)?;
@@ -368,7 +368,7 @@ impl ::serde::ser::Serialize for PaperAccessError {
368368
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
369369
// union serializer
370370
use serde::ser::SerializeStruct;
371-
match *self {
371+
match self {
372372
PaperAccessError::PaperDisabled => {
373373
// unit
374374
let mut s = serializer.serialize_struct("PaperAccessError", 1)?;
@@ -558,7 +558,7 @@ impl ::serde::ser::Serialize for RateLimitReason {
558558
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
559559
// union serializer
560560
use serde::ser::SerializeStruct;
561-
match *self {
561+
match self {
562562
RateLimitReason::TooManyRequests => {
563563
// unit
564564
let mut s = serializer.serialize_struct("RateLimitReason", 1)?;
@@ -737,7 +737,7 @@ impl ::serde::ser::Serialize for TokenFromOAuth1Error {
737737
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
738738
// union serializer
739739
use serde::ser::SerializeStruct;
740-
match *self {
740+
match self {
741741
TokenFromOAuth1Error::InvalidOauth1TokenInfo => {
742742
// unit
743743
let mut s = serializer.serialize_struct("TokenFromOAuth1Error", 1)?;

src/generated/types/common.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@ impl ::serde::ser::Serialize for PathRoot {
8686
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
8787
// union serializer
8888
use serde::ser::SerializeStruct;
89-
match *self {
89+
match self {
9090
PathRoot::Home => {
9191
// unit
9292
let mut s = serializer.serialize_struct("PathRoot", 1)?;
9393
s.serialize_field(".tag", "home")?;
9494
s.end()
9595
}
96-
PathRoot::Root(ref x) => {
96+
PathRoot::Root(x) => {
9797
// primitive
9898
let mut s = serializer.serialize_struct("PathRoot", 2)?;
9999
s.serialize_field(".tag", "root")?;
100100
s.serialize_field("root", x)?;
101101
s.end()
102102
}
103-
PathRoot::NamespaceId(ref x) => {
103+
PathRoot::NamespaceId(x) => {
104104
// primitive
105105
let mut s = serializer.serialize_struct("PathRoot", 2)?;
106106
s.serialize_field(".tag", "namespace_id")?;
@@ -166,8 +166,8 @@ impl ::serde::ser::Serialize for PathRootError {
166166
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
167167
// union serializer
168168
use serde::ser::SerializeStruct;
169-
match *self {
170-
PathRootError::InvalidRoot(ref x) => {
169+
match self {
170+
PathRootError::InvalidRoot(x) => {
171171
// union or polymporphic struct
172172
let mut s = serializer.serialize_struct("PathRootError", 2)?;
173173
s.serialize_field(".tag", "invalid_root")?;
@@ -244,14 +244,14 @@ impl ::serde::ser::Serialize for RootInfo {
244244
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
245245
// polymorphic struct serializer
246246
use serde::ser::SerializeStruct;
247-
match *self {
248-
RootInfo::Team(ref x) => {
247+
match self {
248+
RootInfo::Team(x) => {
249249
let mut s = serializer.serialize_struct("RootInfo", 4)?;
250250
s.serialize_field(".tag", "team")?;
251251
x.internal_serialize::<S>(&mut s)?;
252252
s.end()
253253
}
254-
RootInfo::User(ref x) => {
254+
RootInfo::User(x) => {
255255
let mut s = serializer.serialize_struct("RootInfo", 3)?;
256256
s.serialize_field(".tag", "user")?;
257257
x.internal_serialize::<S>(&mut s)?;

src/generated/types/contacts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ impl ::serde::ser::Serialize for DeleteManualContactsError {
149149
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
150150
// union serializer
151151
use serde::ser::SerializeStruct;
152-
match *self {
153-
DeleteManualContactsError::ContactsNotFound(ref x) => {
152+
match self {
153+
DeleteManualContactsError::ContactsNotFound(x) => {
154154
// primitive
155155
let mut s = serializer.serialize_struct("DeleteManualContactsError", 2)?;
156156
s.serialize_field(".tag", "contacts_not_found")?;

src/generated/types/dbx_async.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl ::serde::ser::Serialize for LaunchEmptyResult {
6161
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
6262
// union serializer
6363
use serde::ser::SerializeStruct;
64-
match *self {
65-
LaunchEmptyResult::AsyncJobId(ref x) => {
64+
match self {
65+
LaunchEmptyResult::AsyncJobId(x) => {
6666
// primitive
6767
let mut s = serializer.serialize_struct("LaunchEmptyResult", 2)?;
6868
s.serialize_field(".tag", "async_job_id")?;
@@ -136,8 +136,8 @@ impl ::serde::ser::Serialize for LaunchResultBase {
136136
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
137137
// union serializer
138138
use serde::ser::SerializeStruct;
139-
match *self {
140-
LaunchResultBase::AsyncJobId(ref x) => {
139+
match self {
140+
LaunchResultBase::AsyncJobId(x) => {
141141
// primitive
142142
let mut s = serializer.serialize_struct("LaunchResultBase", 2)?;
143143
s.serialize_field(".tag", "async_job_id")?;
@@ -285,7 +285,7 @@ impl ::serde::ser::Serialize for PollEmptyResult {
285285
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
286286
// union serializer
287287
use serde::ser::SerializeStruct;
288-
match *self {
288+
match self {
289289
PollEmptyResult::InProgress => {
290290
// unit
291291
let mut s = serializer.serialize_struct("PollEmptyResult", 1)?;
@@ -359,7 +359,7 @@ impl ::serde::ser::Serialize for PollError {
359359
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
360360
// union serializer
361361
use serde::ser::SerializeStruct;
362-
match *self {
362+
match self {
363363
PollError::InvalidAsyncJobId => {
364364
// unit
365365
let mut s = serializer.serialize_struct("PollError", 1)?;
@@ -431,7 +431,7 @@ impl ::serde::ser::Serialize for PollResultBase {
431431
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
432432
// union serializer
433433
use serde::ser::SerializeStruct;
434-
match *self {
434+
match self {
435435
PollResultBase::InProgress => {
436436
// unit
437437
let mut s = serializer.serialize_struct("PollResultBase", 1)?;

0 commit comments

Comments
 (0)