From c7110a8036f530efd8917a79ea4054e055bfee36 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 25 Feb 2023 22:17:27 +0500 Subject: [PATCH] Fix generation of non-existent lifetime 'de when enum contains a #[serde(flatten)] field and a 'static reference --- serde_derive/src/de.rs | 2 +- test_suite/tests/test_gen.rs | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index a703adaf7d..f9d23926cb 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -1006,7 +1006,7 @@ fn deserialize_struct( fn deserialize<__D>(self, __deserializer: __D) -> _serde::__private::Result where - __D: _serde::Deserializer<'de>, + __D: _serde::Deserializer<#delife>, { _serde::Deserializer::deserialize_map(__deserializer, self) } diff --git a/test_suite/tests/test_gen.rs b/test_suite/tests/test_gen.rs index c053d69031..f6782f68f2 100644 --- a/test_suite/tests/test_gen.rs +++ b/test_suite/tests/test_gen.rs @@ -892,3 +892,53 @@ pub struct RemotePackedNonCopyDef { impl Drop for RemotePackedNonCopyDef { fn drop(&mut self) {} } + +////////////////////////////////////////////////////////////////////////// + +/// Regression tests for +#[allow(dead_code)] +mod static_and_flatten { + use super::*; + + #[derive(Deserialize)] + struct Nested; + + #[derive(Deserialize)] + enum ExternallyTagged { + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, + } + + #[derive(Deserialize)] + #[serde(tag = "tag")] + enum InternallyTagged { + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, + } + + #[derive(Deserialize)] + #[serde(tag = "tag", content = "content")] + enum AdjacentlyTagged { + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, + } + + #[derive(Deserialize)] + #[serde(untagged)] + enum UntaggedWorkaround { + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, + } +}