Fix codegen with lifetimes but no type parameters

This commit is contained in:
David Tolnay 2016-08-19 11:12:38 -04:00
parent 6723da67b3
commit a732b9bad3
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 11 additions and 1 deletions

View File

@ -192,7 +192,7 @@ fn deserialize_visitor(
builder: &aster::AstBuilder,
generics: &ast::Generics,
) -> (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.ty().id("__Visitor"),

View File

@ -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::<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>>();
}
//////////////////////////////////////////////////////////////////////////