chiark / gitweb /
config macros: Detect duplicate skl assignment
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 18:58:54 +0000 (19:58 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 18:58:54 +0000 (19:58 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
macros/macros.rs

index a4330dd63c9696f37a9387751a0531a5923e7564..771448e2113d67c9ec543c26d4eb516a8b62d63d 100644 (file)
@@ -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();