File tree 4 files changed +45
-6
lines changed
4 files changed +45
-6
lines changed Original file line number Diff line number Diff line change @@ -2882,13 +2882,14 @@ fn wrap_deserialize_with(
2882
2882
let ( de_impl_generics, de_ty_generics, ty_generics, where_clause) =
2883
2883
split_with_de_lifetime ( params) ;
2884
2884
let delife = params. borrowed . de_lifetime ( ) ;
2885
+ let deserializer_var = quote ! ( __deserializer) ;
2885
2886
2886
2887
// If #deserialize_with returns wrong type, error will be reported here (^^^^^).
2887
2888
// We attach span of the path to the function so it will be reported
2888
2889
// on the #[serde(with = "...")]
2889
2890
// ^^^^^
2890
2891
let value = quote_spanned ! { deserialize_with. span( ) =>
2891
- #deserialize_with( __deserializer ) ?
2892
+ #deserialize_with( #deserializer_var ) ?
2892
2893
} ;
2893
2894
let wrapper = quote ! {
2894
2895
#[ doc( hidden) ]
@@ -2899,7 +2900,7 @@ fn wrap_deserialize_with(
2899
2900
}
2900
2901
2901
2902
impl #de_impl_generics _serde:: Deserialize <#delife> for __DeserializeWith #de_ty_generics #where_clause {
2902
- fn deserialize<__D>( __deserializer : __D) -> _serde:: __private:: Result <Self , __D:: Error >
2903
+ fn deserialize<__D>( #deserializer_var : __D) -> _serde:: __private:: Result <Self , __D:: Error >
2903
2904
where
2904
2905
__D: _serde:: Deserializer <#delife>,
2905
2906
{
Original file line number Diff line number Diff line change @@ -1220,12 +1220,15 @@ fn wrap_serialize_with(
1220
1220
} )
1221
1221
} ) ;
1222
1222
1223
+ let self_var = quote ! ( self ) ;
1224
+ let serializer_var = quote ! ( __s) ;
1225
+
1223
1226
// If #serialize_with returns wrong type, error will be reported on here.
1224
1227
// We attach span of the path to this piece so error will be reported
1225
1228
// on the #[serde(with = "...")]
1226
1229
// ^^^^^
1227
1230
let wrapper_serialize = quote_spanned ! { serialize_with. span( ) =>
1228
- #serialize_with( #( self . values. #field_access, ) * __s )
1231
+ #serialize_with( #( #self_var . values. #field_access, ) * #serializer_var )
1229
1232
} ;
1230
1233
1231
1234
quote ! ( {
@@ -1236,7 +1239,7 @@ fn wrap_serialize_with(
1236
1239
}
1237
1240
1238
1241
impl #wrapper_impl_generics _serde:: Serialize for __SerializeWith #wrapper_ty_generics #where_clause {
1239
- fn serialize<__S>( & self , __s : __S) -> _serde:: __private:: Result <__S:: Ok , __S:: Error >
1242
+ fn serialize<__S>( & #self_var , #serializer_var : __S) -> _serde:: __private:: Result <__S:: Ok , __S:: Error >
1240
1243
where
1241
1244
__S: _serde:: Serializer ,
1242
1245
{
Original file line number Diff line number Diff line change
1
+ use serde_derive:: { Deserialize , Serialize } ;
2
+
3
+ macro_rules! declare_in_macro {
4
+ ( $with: literal) => {
5
+ #[ derive( Serialize , Deserialize ) ]
6
+ pub struct S {
7
+ #[ serde( with = $with) ]
8
+ f: i32 ,
9
+ }
10
+ } ;
11
+ }
12
+
13
+ declare_in_macro ! ( "with" ) ;
14
+
15
+ mod with {
16
+ use serde:: { Deserializer , Serializer } ;
17
+
18
+ pub fn serialize < S > ( _: & i32 , _: S ) -> Result < S :: Ok , S :: Error >
19
+ where
20
+ S : Serializer ,
21
+ {
22
+ unimplemented ! ( )
23
+ }
24
+
25
+ pub fn deserialize < ' de , D > ( _: D ) -> Result < i32 , D :: Error >
26
+ where
27
+ D : Deserializer < ' de > ,
28
+ {
29
+ unimplemented ! ( )
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -19,8 +19,10 @@ note: required by a bound in `w::serialize`
19
19
error[E0061]: this function takes 1 argument but 2 arguments were supplied
20
20
--> tests/ui/with/incorrect_type.rs:15:25
21
21
|
22
+ 14 | #[derive(Serialize, Deserialize)]
23
+ | --------- unexpected argument #2 of type `__S`
22
24
15 | struct W(#[serde(with = "w")] u8, u8);
23
- | ^^^ unexpected argument #2 of type `__S`
25
+ | ^^^
24
26
|
25
27
note: function defined here
26
28
--> tests/ui/with/incorrect_type.rs:9:12
@@ -68,8 +70,10 @@ note: required by a bound in `w::serialize`
68
70
error[E0061]: this function takes 1 argument but 2 arguments were supplied
69
71
--> tests/ui/with/incorrect_type.rs:18:35
70
72
|
73
+ 17 | #[derive(Serialize, Deserialize)]
74
+ | --------- unexpected argument #2 of type `__S`
71
75
18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);
72
- | ^^^^^^^^^^^^^^ unexpected argument #2 of type `__S`
76
+ | ^^^^^^^^^^^^^^
73
77
|
74
78
note: function defined here
75
79
--> tests/ui/with/incorrect_type.rs:9:12
You can’t perform that action at this time.
0 commit comments