From d5e5c520ac1a2c977848ce4f3f6cda5815f12fc5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 3 Nov 2017 10:08:02 -0700 Subject: [PATCH] Ignore skipped fields when looking for borrowed lifetimes --- serde_derive/src/de.rs | 4 +++- test_suite/tests/test_gen.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index 44ed7fa0..71326b84 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -203,7 +203,9 @@ impl BorrowedLifetimes { fn borrowed_lifetimes(cont: &Container) -> BorrowedLifetimes { let mut lifetimes = BTreeSet::new(); for field in cont.body.all_fields() { - lifetimes.extend(field.attrs.borrowed_lifetimes().iter().cloned()); + if !field.attrs.skip_deserializing() { + lifetimes.extend(field.attrs.borrowed_lifetimes().iter().cloned()); + } } if lifetimes.iter().any(|b| b.ident == "'static") { BorrowedLifetimes::Static diff --git a/test_suite/tests/test_gen.rs b/test_suite/tests/test_gen.rs index f9143099..50cd13b7 100644 --- a/test_suite/tests/test_gen.rs +++ b/test_suite/tests/test_gen.rs @@ -511,6 +511,14 @@ fn test_gen() { Tuple(&'a str, &'static str), Newtype(&'static str), } + + #[derive(Serialize, Deserialize)] + struct SkippedStaticStr { + #[serde(skip_deserializing)] + skipped: &'static str, + other: isize, + } + assert::(); } //////////////////////////////////////////////////////////////////////////