From: Ian Jackson Date: Sat, 7 Aug 2021 18:58:54 +0000 (+0100) Subject: config macros: Detect duplicate skl assignment X-Git-Tag: hippotat/1.0.0~263 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=0069283360c3e23e63dad06744df8e1399252e1a;p=hippotat.git config macros: Detect duplicate skl assignment Signed-off-by: Ian Jackson --- diff --git a/macros/macros.rs b/macros/macros.rs index a4330dd..771448e 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -65,25 +65,29 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let fname = &field.ident.as_ref().unwrap(); let fname_span = fname.span(); let mut skl = None; + let mut set_skl = |new| { + if let Some(old) = &skl { panic!("dup SKL {} and {} for field {}", + old, new, &fname); } + skl = Some(new); + }; let mut method = quote_spanned!{fname_span=> ordinary }; for attr in &field.attrs { let atspan = attr.path.segments.last().unwrap().ident.span(); if attr.tokens.is_empty() { if &attr.path == &parse_quote!{ per_client } { - skl = Some(quote_spanned!{fname_span=> SectionKindList::PerClient }); + set_skl(quote_spanned!{fname_span=> SectionKindList::PerClient }); continue; } else if &attr.path == &parse_quote!{ global } { - skl = Some(quote_spanned!{fname_span=> - SectionKindList::Global }); + set_skl(quote_spanned!{fname_span=> SectionKindList::Global }); continue; } method = attr.path.to_token_stream(); if &attr.path == &parse_quote!{ limited } { - skl = Some(quote_spanned!{atspan=> SectionKindList::Limited }); + set_skl(quote_spanned!{atspan=> SectionKindList::Limited }); } else if &attr.path == &parse_quote!{ client } { - skl = Some(quote_spanned!{atspan=> SectionKindList::PerClient }); + set_skl(quote_spanned!{atspan=> SectionKindList::PerClient }); } else if &attr.path == &parse_quote!{ computed } { - skl = Some(quote_spanned!{atspan=> SectionKindList::None }); + set_skl(quote_spanned!{atspan=> SectionKindList::None }); } } else if &attr.path == &parse_quote!{ special } { let meta = match attr.parse_meta().unwrap() { @@ -98,7 +102,7 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { } } method = get_path(tmethod); - skl = Some(get_path(tskl)); + set_skl(get_path(tskl)); } } let fname_string = fname.to_string();