Block #[cfg] attributes on exported or inner functions

This commit is contained in:
J Henry Waugh
2020-08-21 22:30:10 -05:00
parent 15a8f528ae
commit 708c0f385e
6 changed files with 95 additions and 0 deletions

View File

@@ -16,6 +16,17 @@ use std::borrow::Cow;
use std::collections::HashMap;
fn inner_fn_attributes(f: &mut syn::ItemFn) -> syn::Result<ExportedFnParams> {
// #[cfg] attributes are not allowed on objects
if let Some(cfg_attr) = f.attrs.iter().find(|a| {
a.path
.get_ident()
.map(|i| i.to_string() == "cfg")
.unwrap_or(false)
}) {
return Err(syn::Error::new(cfg_attr.span(), "cfg attributes not allowed on this item"));
}
// Find the #[rhai_fn] attribute which will turn be read for the function parameters.
if let Some(rhai_fn_idx) = f.attrs.iter().position(|a| {
a.path
.get_ident()