diff --git a/serde_macros/src/lib.rs b/serde_macros/src/lib.rs index d1ac9696..e92a9786 100644 --- a/serde_macros/src/lib.rs +++ b/serde_macros/src/lib.rs @@ -706,6 +706,10 @@ fn deserialize_struct( visitor_ty: P, visitor_expr: P, ) -> P { + let value_ty = builder.ty().path() + .segment(type_ident).with_generics(trait_generics.clone()).build() + .build(); + match *fields { Unnamed(ref fields) => { if fields.is_empty() { @@ -720,7 +724,6 @@ fn deserialize_struct( deserialize_struct_unnamed_fields( cx, builder, - type_ident, struct_ident, struct_path, &fields, @@ -729,6 +732,7 @@ fn deserialize_struct( visitor_item, visitor_ty, visitor_expr, + value_ty, ) } } @@ -737,7 +741,6 @@ fn deserialize_struct( cx, span, builder, - type_ident, struct_ident, struct_path, &fields, @@ -747,6 +750,7 @@ fn deserialize_struct( visitor_item, visitor_ty, visitor_expr, + value_ty, ) } } @@ -804,7 +808,6 @@ fn deserialize_struct_empty_fields( fn deserialize_struct_unnamed_fields( cx: &ExtCtxt, builder: &aster::AstBuilder, - type_ident: Ident, struct_ident: Ident, struct_path: ast::Path, fields: &[Span], @@ -813,6 +816,7 @@ fn deserialize_struct_unnamed_fields( visitor_item: P, visitor_ty: P, visitor_expr: P, + value_ty: P, ) -> P { let where_clause = &trait_generics.where_clause; @@ -829,10 +833,6 @@ fn deserialize_struct_unnamed_fields( let struct_name = builder.expr().str(struct_ident); - let value_ty = builder.ty().path() - .segment(type_ident).with_generics(trait_generics.clone()).build() - .build(); - quote_expr!(cx, { $visitor_item @@ -899,7 +899,6 @@ fn deserialize_struct_named_fields( cx: &ExtCtxt, span: Span, builder: &aster::AstBuilder, - type_ident: Ident, struct_ident: Ident, struct_path: ast::Path, fields: &[(Ident, Span)], @@ -909,6 +908,7 @@ fn deserialize_struct_named_fields( visitor_item: P, visitor_ty: P, visitor_expr: P, + value_ty: P, ) -> P { let where_clause = &trait_generics.where_clause; @@ -917,12 +917,6 @@ fn deserialize_struct_named_fields( .map(|i| token::str_to_ident(&format!("__field{}", i))) .collect(); - let struct_name = builder.expr().str(struct_ident); - - let value_ty = builder.ty().path() - .segment(type_ident).with_generics(trait_generics.clone()).build() - .build(); - let field_devisitor = declare_map_field_devisitor( cx, span, @@ -941,6 +935,8 @@ fn deserialize_struct_named_fields( struct_def ); + let struct_name = builder.expr().str(struct_ident); + quote_expr!(cx, { $field_devisitor