@@ -10,6 +10,15 @@ use std::{
10
10
} ;
11
11
use syn:: { spanned:: Spanned , DataEnum , DataStruct , DataUnion , DeriveInput , Lit } ;
12
12
13
+ macro_rules! empty_meta {
14
+ ( $meta: expr) => { {
15
+ let _ = $meta
16
+ . value( )
17
+ . map( |val| val. parse:: <TokenStream >( ) . unwrap( ) )
18
+ . unwrap_or_else( |_| $meta. input. cursor( ) . token_stream( ) ) ;
19
+ } } ;
20
+ }
21
+
13
22
fn print_warning (
14
23
span : proc_macro2:: Span ,
15
24
title : impl Display ,
@@ -102,31 +111,35 @@ impl SerdeContainerOptions {
102
111
. filter ( |attr| attr. path ( ) . is_ident ( "serde" ) )
103
112
{
104
113
attribute. parse_nested_meta ( |meta| {
105
- if meta. path . is_ident ( "rename_all" ) {
114
+ if meta. path . is_ident ( "crate" ) {
115
+ // ignore the serde crate annotation. we don't really care for that.
116
+ empty_meta ! ( meta) ;
117
+ } else if meta. path . is_ident ( "rename_all" ) {
106
118
options. rename_all = Some ( meta. value ( ) ?. parse ( ) ?) ;
107
119
} else if meta. path . is_ident ( "untagged" ) {
108
120
options. untagged = true ;
109
121
} else {
110
- print_warning (
111
- meta. path . span ( ) ,
112
- "unknown serde attribute" ,
113
- format ! (
114
- "unknown attribute \" {}\" " ,
115
- meta. path
116
- . get_ident( )
117
- . map( |ident| ident. to_string( ) )
118
- . unwrap_or_else( || "[error]" . into( ) )
119
- ) ,
120
- )
121
- . unwrap ( ) ;
122
+ if !muted_warnings {
123
+ print_warning (
124
+ meta. path . span ( ) ,
125
+ "unknown serde attribute" ,
126
+ format ! (
127
+ "unknown attribute \" {}\" " ,
128
+ meta. path
129
+ . get_ident( )
130
+ . map( |ident| ident. to_string( ) )
131
+ . unwrap_or_else( || "[error]" . into( ) )
132
+ ) ,
133
+ )
134
+ . unwrap ( ) ;
135
+ }
122
136
123
137
// TODO: support other serde attributes
124
138
//
139
+ // See: <https://github.com/CosmWasm/cosmwasm/issues/2499>
140
+ //
125
141
// For now we simply clear the buffer to avoid errors
126
- let _ = meta
127
- . value ( )
128
- . map ( |val| val. parse :: < TokenStream > ( ) . unwrap ( ) )
129
- . unwrap_or_else ( |_| meta. input . cursor ( ) . token_stream ( ) ) ;
142
+ empty_meta ! ( meta) ;
130
143
}
131
144
132
145
if ( meta. path . is_ident ( "untagged" ) || meta. path . is_ident ( "tag" ) ) && !muted_warnings
@@ -214,7 +227,7 @@ impl SerdeFieldOptions {
214
227
options. default = true ;
215
228
// just ignore the rest. it's not relevant.
216
229
// but without this code, we'd sometimes hit compile errors.
217
- let _ = meta . value ( ) . and_then ( |val| val . parse :: < syn :: Expr > ( ) ) ;
230
+ empty_meta ! ( meta ) ;
218
231
} else if meta. path . is_ident ( "skip_serializing_if" ) {
219
232
options. skip_serializing_if = Some ( meta. value ( ) ?. parse ( ) ?) ;
220
233
} else {
@@ -235,11 +248,10 @@ impl SerdeFieldOptions {
235
248
236
249
// TODO: support other serde attributes
237
250
//
251
+ // See: <https://github.com/CosmWasm/cosmwasm/issues/2499>
252
+ //
238
253
// For now we simply clear the buffer to avoid errors
239
- let _ = meta
240
- . value ( )
241
- . map ( |val| val. parse :: < TokenStream > ( ) . unwrap ( ) )
242
- . unwrap_or_else ( |_| meta. input . cursor ( ) . token_stream ( ) ) ;
254
+ empty_meta ! ( meta) ;
243
255
}
244
256
245
257
Ok ( ( ) )
0 commit comments