chiark / gitweb /
config: Introduce SKL::None, currently for `computed`
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 17:33:34 +0000 (18:33 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 18:46:01 +0000 (19:46 +0100)
This isn't complete yet, because we need to use this in more places
and also arrange not to treat these as "allowed but in the wrong
section" but "not a known config key".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
macros/macros.rs
src/config.rs

index 64501be8d62f696554ea284e778b964620464547..9d64c245fb7a13d96d98d2fd1c48783054e58180 100644 (file)
@@ -70,6 +70,8 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
         method = attr.path.to_token_stream();
         if &attr.path == &parse_quote!{ limited } {
           skl = quote_spanned!{atspan=> SectionKindList::Limited };
+        } else if &attr.path == &parse_quote!{ computed } {
+          skl = quote_spanned!{atspan=> SectionKindList::None };
         }
       } else if &attr.path == &parse_quote!{ special } {
         let meta = match attr.parse_meta().unwrap() {
index 6a5e6bf560a7a20d2d7fd8b43e2a922f1fbb1cff..d771a105b499ebadee0be00e5d9d0625b936cb43 100644 (file)
@@ -521,6 +521,7 @@ enum SectionKindList {
   Limits,
   Global,
   ServerName,
+  None,
 }
 use SectionKindList as SKL;
 
@@ -550,6 +551,7 @@ impl SectionKindList {
       SKL::ServerName     => matches!(s, SN::Common)
                            | matches!(s, SN::Server(ServerName(name))
                                          if name == SPECIAL_SERVER_SECTION),
+      SKL::None           => false,
     }
   }
 }
@@ -650,9 +652,10 @@ impl<'c> ResolveContext<'c> {
   }
 
   #[throws(AE)]
-  pub fn computed<T>(&self, _key: &'static str, _skl: SKL) -> T
+  pub fn computed<T>(&self, _key: &'static str, skl: SKL) -> T
   where T: Default
   {
+    assert_eq!(skl, SKL::None);
     default()
   }