Auto merge of #509 - serde-rs:cow, r=oli-obk

Fix codegen with lifetimes but no type parameters

Fixes #507.
This commit is contained in:
Homu 2016-08-20 00:16:54 +09:00
commit 7aba920dec
2 changed files with 11 additions and 1 deletions

View File

@ -192,7 +192,7 @@ fn deserialize_visitor(
builder: &aster::AstBuilder, builder: &aster::AstBuilder,
generics: &ast::Generics, generics: &ast::Generics,
) -> (P<ast::Item>, P<ast::Ty>, P<ast::Expr>) { ) -> (P<ast::Item>, P<ast::Ty>, P<ast::Expr>) {
if generics.ty_params.is_empty() { if generics.lifetimes.is_empty() && generics.ty_params.is_empty() {
( (
builder.item().unit_struct("__Visitor"), builder.item().unit_struct("__Visitor"),
builder.ty().id("__Visitor"), builder.ty().id("__Visitor"),

View File

@ -6,6 +6,7 @@ extern crate serde;
use self::serde::ser::{Serialize, Serializer}; use self::serde::ser::{Serialize, Serializer};
use self::serde::de::{Deserialize, Deserializer}; use self::serde::de::{Deserialize, Deserializer};
use std::borrow::Cow;
use std::marker::PhantomData; use std::marker::PhantomData;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -177,6 +178,15 @@ fn test_gen() {
e: E, e: E,
} }
assert::<WithTraits2<X, X>>(); assert::<WithTraits2<X, X>>();
#[derive(Serialize, Deserialize)]
struct CowStr<'a>(Cow<'a, str>);
assert::<CowStr>();
#[derive(Serialize, Deserialize)]
#[serde(bound(deserialize = "T::Owned: Deserialize"))]
struct CowT<'a, T: ?Sized + 'a + ToOwned>(Cow<'a, T>);
assert::<CowT<str>>();
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////