Skip to content

Commit

Permalink
Correctly calculate serialized enum style for deserialization
Browse files Browse the repository at this point in the history
Changes in generated code (see the file attached to PR):
  AdjacentlyTagged, Untagged, Mixed:
    Tuple0: tuple(0) -> unit

    Tuple2as0: tuple(0) -> unit
    Tuple2as1: tuple(1) -> newtype

    Tuple2as0Default: tuple(0) -> unit
    Tuple2as1Default: tuple(1) -> newtype

    Tuple2as0With: tuple(0) -> unit
    Tuple2as1With: tuple(1) -> newtype
  • Loading branch information
Mingun committed Jul 31, 2023
1 parent 93fb53a commit 32f2c49
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ fn deserialize_internally_tagged_variant(

let variant_ident = &variant.ident;

match effective_style(variant) {
match variant.de_style() {
Style::Unit => {
let this_value = &params.this_value;
let type_name = params.type_name();
Expand Down Expand Up @@ -1949,7 +1949,7 @@ fn deserialize_untagged_variant(

let variant_ident = &variant.ident;

match effective_style(variant) {
match variant.de_style() {
Style::Unit => {
let this_value = &params.this_value;
let type_name = params.type_name();
Expand Down Expand Up @@ -3108,13 +3108,6 @@ fn expr_is_missing(field: &Field, cattrs: &attr::Container) -> Fragment {
}
}

fn effective_style(variant: &Variant) -> Style {
match variant.style {
Style::Newtype if variant.fields[0].attrs.skip_deserializing() => Style::Unit,
other => other,
}
}

/// Constructs a tuple variant with default values of all fields
fn construct_default_tuple(variant: &Variant, cattrs: &attr::Container) -> Option<TokenStream> {
// Tuple variant with some fields, including newtype variant
Expand Down

0 comments on commit 32f2c49

Please sign in to comment.