mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 13:47:58 +00:00
fix(codegen): Discard type defaults from impl generics
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user