Allow #[cfg(...)] in plugin functions.

This commit is contained in:
Stephen Chung
2021-10-20 15:30:11 +08:00
parent 0265af415d
commit 3f2dd23e6e
8 changed files with 141 additions and 38 deletions

View File

@@ -129,16 +129,10 @@ pub fn inner_item_attributes<T: ExportedParams>(
}
}
pub fn deny_cfg_attr(attrs: &[syn::Attribute]) -> syn::Result<()> {
if let Some(cfg_attr) = attrs
pub fn collect_cfg_attr(attrs: &[syn::Attribute]) -> Vec<syn::Attribute> {
attrs
.iter()
.find(|a| a.path.get_ident().map(|i| *i == "cfg").unwrap_or(false))
{
Err(syn::Error::new(
cfg_attr.span(),
"cfg attributes not allowed on this item",
))
} else {
Ok(())
}
.filter(|&a| a.path.get_ident().map(|i| *i == "cfg").unwrap_or(false))
.cloned()
.collect()
}