fix(codegen): Discard type defaults from impl generics

This commit is contained in:
David Tolnay
2016-04-13 23:51:04 -07:00
parent 808b06940e
commit fd3c15fb68
4 changed files with 50 additions and 3 deletions
+14
View File
@@ -7,6 +7,20 @@ use syntax::ext::base::ExtCtxt;
use syntax::ptr::P;
use syntax::visit;
// Remove the default from every type parameter because in the generated impls
// they look like associated types: "error: associated type bindings are not
// allowed here".
pub fn without_defaults(generics: &ast::Generics) -> ast::Generics {
ast::Generics {
ty_params: generics.ty_params.map(|ty_param| {
ast::TyParam {
default: None,
.. ty_param.clone()
}}),
.. generics.clone()
}
}
pub fn with_bound(
cx: &ExtCtxt,
builder: &AstBuilder,
+2 -1
View File
@@ -85,7 +85,8 @@ fn build_impl_generics(
item: &Item,
generics: &ast::Generics,
) -> ast::Generics {
let generics = bound::with_bound(cx, builder, item, generics,
let generics = bound::without_defaults(generics);
let generics = bound::with_bound(cx, builder, item, &generics,
&deserialized_by_us,
&["serde", "de", "Deserialize"]);
let generics = bound::with_bound(cx, builder, item, &generics,
+4 -2
View File
@@ -93,9 +93,11 @@ fn build_impl_generics(
item: &Item,
generics: &ast::Generics,
) -> ast::Generics {
bound::with_bound(cx, builder, item, generics,
let generics = bound::without_defaults(generics);
let generics = bound::with_bound(cx, builder, item, &generics,
&serialized_by_us,
&["serde", "ser", "Serialize"])
&["serde", "ser", "Serialize"]);
generics
}
// Fields with a `skip_serializing` or `serialize_with` attribute are not