From 3cd9d071c2a03f0a02470d584732ec32f1f96609 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 6 May 2018 21:49:37 -0700 Subject: [PATCH] Fix adjacently tagged empty tuple variant or struct variant --- serde_derive/src/ser.rs | 2 +- test_suite/tests/test_gen.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index 987cc53a..38b03eec 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -645,7 +645,7 @@ fn serialize_adjacently_tagged_variant( let (_, ty_generics, where_clause) = params.generics.split_for_impl(); - let wrapper_generics = if let Style::Unit = variant.style { + let wrapper_generics = if fields_ident.is_empty() { params.generics.clone() } else { bound::with_lifetime_bound(¶ms.generics, "'__a") diff --git a/test_suite/tests/test_gen.rs b/test_suite/tests/test_gen.rs index d6921e14..f0255bad 100644 --- a/test_suite/tests/test_gen.rs +++ b/test_suite/tests/test_gen.rs @@ -567,6 +567,17 @@ fn test_gen() { } assert::>(); + + #[derive(Serialize)] + #[serde(tag = "t", content = "c")] + enum EmptyAdjacentlyTagged { + #[allow(dead_code)] + Struct {}, + #[allow(dead_code)] + Tuple(), + } + + assert_ser::(); } //////////////////////////////////////////////////////////////////////////