aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-22 13:22:58 +0100
committerMartin Fischer <martin@push-f.com>2021-11-22 13:27:32 +0100
commit60132008eebcbaf1d9891ced24be1cfc1f098ecc (patch)
tree925b69b5e8ec446e6f352b2f410643371dd7183c
parent684d7e5873aa0b6423e167124fd8c72e02173ba2 (diff)
parse attributes before associated types
-rw-r--r--src/lib.rs68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1a84a09..13cbce7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -71,6 +71,40 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream {
let mut type_converter = TypeConverter::default();
+ let mut blanket_impl_attrs = Vec::new();
+ let mut dyn_trait_attrs = Vec::new();
+
+ // FUTURE: use Vec::drain_filter once it's stable
+ let mut i = 0;
+ while i < original_trait.attrs.len() {
+ if original_trait.attrs[i].path.is_ident("blanket_impl_attr") {
+ let attr = original_trait.attrs.remove(i);
+ let group: Group = match syn::parse2(attr.tokens) {
+ Ok(g) => g,
+ Err(err) => {
+ return abort!(
+ err.span(),
+ "expected parenthesis: #[blanket_impl_attr(...)]"
+ )
+ }
+ };
+ let tokens = group.stream();
+ blanket_impl_attrs.push(quote! {#[#tokens]});
+ } else if original_trait.attrs[i].path.is_ident("dyn_trait_attr") {
+ let attr = original_trait.attrs.remove(i);
+ let group: Group = match syn::parse2(attr.tokens) {
+ Ok(g) => g,
+ Err(err) => {
+ return abort!(err.span(), "expected parenthesis: #[dyn_trait_attr(...)]")
+ }
+ };
+ let tokens = group.stream();
+ dyn_trait_attrs.push(quote! {#[#tokens]});
+ } else {
+ i += 1;
+ }
+ }
+
for item in &original_trait.items {
if let TraitItem::Type(assoc_type) = item {
match parse_assoc_type(assoc_type) {
@@ -146,40 +180,6 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream {
let mut method_impls: Vec<ImplItemMethod> = Vec::new();
- let mut blanket_impl_attrs = Vec::new();
- let mut dyn_trait_attrs = Vec::new();
-
- // FUTURE: use Vec::drain_filter once it's stable
- let mut i = 0;
- while i < original_trait.attrs.len() {
- if original_trait.attrs[i].path.is_ident("blanket_impl_attr") {
- let attr = original_trait.attrs.remove(i);
- let group: Group = match syn::parse2(attr.tokens) {
- Ok(g) => g,
- Err(err) => {
- return abort!(
- err.span(),
- "expected parenthesis: #[blanket_impl_attr(...)]"
- )
- }
- };
- let tokens = group.stream();
- blanket_impl_attrs.push(quote! {#[#tokens]});
- } else if original_trait.attrs[i].path.is_ident("dyn_trait_attr") {
- let attr = original_trait.attrs.remove(i);
- let group: Group = match syn::parse2(attr.tokens) {
- Ok(g) => g,
- Err(err) => {
- return abort!(err.span(), "expected parenthesis: #[dyn_trait_attr(...)]")
- }
- };
- let tokens = group.stream();
- dyn_trait_attrs.push(quote! {#[#tokens]});
- } else {
- i += 1;
- }
- }
-
let mut dyn_trait = ItemTrait {
ident: format_ident!("Dyn{}", original_trait.ident),