Skip to content

Commit

Permalink
Fix generation of non-existent lifetime 'de when enum contains a #[se…
Browse files Browse the repository at this point in the history
…rde(flatten)] field and a 'static reference
  • Loading branch information
Mingun committed Feb 25, 2023
1 parent f85c4f2 commit c7110a8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ fn deserialize_struct(

fn deserialize<__D>(self, __deserializer: __D) -> _serde::__private::Result<Self::Value, __D::Error>
where
__D: _serde::Deserializer<'de>,
__D: _serde::Deserializer<#delife>,
{
_serde::Deserializer::deserialize_map(__deserializer, self)
}
Expand Down
50 changes: 50 additions & 0 deletions test_suite/tests/test_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,3 +892,53 @@ pub struct RemotePackedNonCopyDef {
impl Drop for RemotePackedNonCopyDef {
fn drop(&mut self) {}
}

//////////////////////////////////////////////////////////////////////////

/// Regression tests for <https://github.com/serde-rs/serde/issues/2371>
#[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,
},
}
}

0 comments on commit c7110a8

Please sign in to comment.