From a732b9bad36ef3384334a5e4706b1ccc298720cc Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 19 Aug 2016 11:12:38 -0400 Subject: [PATCH] Fix codegen with lifetimes but no type parameters --- serde_codegen/src/de.rs | 2 +- testing/tests/test_gen.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/serde_codegen/src/de.rs b/serde_codegen/src/de.rs index bbcb30e9..b630ede0 100644 --- a/serde_codegen/src/de.rs +++ b/serde_codegen/src/de.rs @@ -192,7 +192,7 @@ fn deserialize_visitor( builder: &aster::AstBuilder, generics: &ast::Generics, ) -> (P, P, P) { - if generics.ty_params.is_empty() { + if generics.lifetimes.is_empty() && generics.ty_params.is_empty() { ( builder.item().unit_struct("__Visitor"), builder.ty().id("__Visitor"), diff --git a/testing/tests/test_gen.rs b/testing/tests/test_gen.rs index 0acfdb36..7d648f57 100644 --- a/testing/tests/test_gen.rs +++ b/testing/tests/test_gen.rs @@ -6,6 +6,7 @@ extern crate serde; use self::serde::ser::{Serialize, Serializer}; use self::serde::de::{Deserialize, Deserializer}; +use std::borrow::Cow; use std::marker::PhantomData; ////////////////////////////////////////////////////////////////////////// @@ -177,6 +178,15 @@ fn test_gen() { e: E, } assert::>(); + + #[derive(Serialize, Deserialize)] + struct CowStr<'a>(Cow<'a, str>); + assert::(); + + #[derive(Serialize, Deserialize)] + #[serde(bound(deserialize = "T::Owned: Deserialize"))] + struct CowT<'a, T: ?Sized + 'a + ToOwned>(Cow<'a, T>); + assert::>(); } //////////////////////////////////////////////////////////////////////////