Skip to content

Commit f7c6bb7

Browse files
committed
Add tracking issue
1 parent 07a5964 commit f7c6bb7

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

packages/cw-schema-derive/src/expand.rs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ use std::{
1010
};
1111
use syn::{spanned::Spanned, DataEnum, DataStruct, DataUnion, DeriveInput, Lit};
1212

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+
1322
fn print_warning(
1423
span: proc_macro2::Span,
1524
title: impl Display,
@@ -102,31 +111,35 @@ impl SerdeContainerOptions {
102111
.filter(|attr| attr.path().is_ident("serde"))
103112
{
104113
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") {
106118
options.rename_all = Some(meta.value()?.parse()?);
107119
} else if meta.path.is_ident("untagged") {
108120
options.untagged = true;
109121
} 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+
}
122136

123137
// TODO: support other serde attributes
124138
//
139+
// See: <https://github.com/CosmWasm/cosmwasm/issues/2499>
140+
//
125141
// 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);
130143
}
131144

132145
if (meta.path.is_ident("untagged") || meta.path.is_ident("tag")) && !muted_warnings
@@ -214,7 +227,7 @@ impl SerdeFieldOptions {
214227
options.default = true;
215228
// just ignore the rest. it's not relevant.
216229
// 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);
218231
} else if meta.path.is_ident("skip_serializing_if") {
219232
options.skip_serializing_if = Some(meta.value()?.parse()?);
220233
} else {
@@ -235,11 +248,10 @@ impl SerdeFieldOptions {
235248

236249
// TODO: support other serde attributes
237250
//
251+
// See: <https://github.com/CosmWasm/cosmwasm/issues/2499>
252+
//
238253
// 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);
243255
}
244256

245257
Ok(())

0 commit comments

Comments
 (0)