diff options
Diffstat (limited to 'src/parse_attrs.rs')
-rw-r--r-- | src/parse_attrs.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/parse_attrs.rs b/src/parse_attrs.rs index 03b5377..d9725ff 100644 --- a/src/parse_attrs.rs +++ b/src/parse_attrs.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use proc_macro2::{Group, TokenStream}; use quote::quote; @@ -33,6 +33,21 @@ pub struct TraitAttrs { pub blanket_impl_attrs: Vec<TokenStream>, pub dyn_trait_attrs: Vec<TokenStream>, pub collections: HashMap<Ident, usize>, + pub dynamized_supertraits: HashSet<Ident>, +} + +struct Dynamized { + ident: Ident, +} + +impl Parse for Dynamized { + fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> { + let inner; + parenthesized!(inner in input); + Ok(Self { + ident: inner.parse()?, + }) + } } impl TraitAttrs { @@ -84,6 +99,18 @@ impl TraitAttrs { ), )); } + } else if attrs[i].path.is_ident("dynamized") { + let attr = attrs.remove(i); + let dynamized: Dynamized = syn::parse2(attr.tokens)?; + let span = dynamized.ident.span(); + + if !parsed.dynamized_supertraits.insert(dynamized.ident) { + // FUTURE: relax to warning once proc_macro::Diagnostic is stable + return Err(Error::new( + span, + format_args!("dynamized attribute is defined multiple times"), + )); + } } else { i += 1; } |