summary refs log tree commit diff stats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2021-08-13 00:11:15 -0300
committerSoniEx2 <endermoneymod@gmail.com>2021-08-13 00:11:15 -0300
commitcf68dd857cd772b47dc46731c6bbb02112f07889 (patch)
tree86c6a971fe4d013701ea121b3bb3304d8154f0ae /src/lib.rs
parenta0f77cbba537514f84f64c5be660f2bdcd69782f (diff)
Make generics work in more places
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 2a3b90f..192d56b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -163,7 +163,11 @@ pub fn impl_trait(item: TokenStream) -> TokenStream {
                     has_injected_generics = true;
                     if generics_scratchpad.is_empty() {
                         found.last_mut().unwrap().extend(generics.clone());
+                    } else if generics.is_empty() {
+                        found.last_mut().unwrap().extend(generics_scratchpad.clone());
                     } else {
+                        // need to *combine* generics. this is not exactly trivial.
+                        // thankfully we don't need to worry about defaults on impls.
                         let mut this_generics: Generics = syn::parse(generics_scratchpad.drain(..).collect()).unwrap();
                         let parent_generics: Generics = syn::parse(generics.clone().into_iter().collect()).unwrap();
                         let mut target = parent_generics.params.into_pairs().chain(this_generics.params.clone().into_pairs()).collect::<Vec<_>>();
@@ -180,6 +184,14 @@ pub fn impl_trait(item: TokenStream) -> TokenStream {
                                 (&GenericParam::Const(_), &GenericParam::Lifetime(_)) => Ordering::Greater,
                             }
                         });
+                        // just need to fix the one Pair::End in the middle of the thing.
+                        for item in &mut target {
+                            if matches!(item, syn::punctuated::Pair::End(_)) {
+                                let value = item.value().clone();
+                                *item = syn::punctuated::Pair::Punctuated(value, syn::token::Comma { spans: [trait_span.unwrap().into()] });
+                                break;
+                            }
+                        }
                         this_generics.params = target.into_iter().collect();
                         let new_generics = TokenStream::from(this_generics.into_token_stream());
                         found.last_mut().unwrap().extend(new_generics);