Skip to content

Commit 45c45e8

Browse files
committed
Fix hand-written enum variant deserializations to allow u64 discriminant
Automatically generated enum variant deserializers allowed any integer type as the discriminant, but the hand-written ones for specific enum types such as Result or IpAddr only allowed types up to u32. This broke some non-human-readable deserializers for these enums, with deserializers that emit any integer type as a u64. Switch the visit_u32 methods to visit_u64 methods to allow discriminants to have any size up to a u64.
1 parent 2e76f70 commit 45c45e8

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

serde/src/de/impls.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,15 +1313,15 @@ macro_rules! variant_identifier {
13131313
formatter.write_str($expecting_message)
13141314
}
13151315

1316-
fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
1316+
fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
13171317
where
13181318
E: Error,
13191319
{
13201320
match value {
13211321
$(
13221322
$index => Ok($name_kind :: $variant),
13231323
)*
1324-
_ => Err(Error::invalid_value(Unexpected::Unsigned(value as u64), &self),),
1324+
_ => Err(Error::invalid_value(Unexpected::Unsigned(value), &self),),
13251325
}
13261326
}
13271327

@@ -2326,7 +2326,7 @@ where
23262326
formatter.write_str("`Unbounded`, `Included` or `Excluded`")
23272327
}
23282328

2329-
fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
2329+
fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
23302330
where
23312331
E: Error,
23322332
{
@@ -2335,7 +2335,7 @@ where
23352335
1 => Ok(Field::Included),
23362336
2 => Ok(Field::Excluded),
23372337
_ => Err(Error::invalid_value(
2338-
Unexpected::Unsigned(value as u64),
2338+
Unexpected::Unsigned(value),
23392339
&self,
23402340
)),
23412341
}
@@ -2492,15 +2492,15 @@ where
24922492
formatter.write_str("`Ok` or `Err`")
24932493
}
24942494

2495-
fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
2495+
fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
24962496
where
24972497
E: Error,
24982498
{
24992499
match value {
25002500
0 => Ok(Field::Ok),
25012501
1 => Ok(Field::Err),
25022502
_ => Err(Error::invalid_value(
2503-
Unexpected::Unsigned(value as u64),
2503+
Unexpected::Unsigned(value),
25042504
&self,
25052505
)),
25062506
}

0 commit comments

Comments
 (0)