|
1 | 1 | use std::convert::TryFrom; |
2 | 2 |
|
3 | 3 | use proc_macro2::{Span, TokenStream}; |
4 | | -use quote::{format_ident, quote, quote_spanned, ToTokens}; |
| 4 | +use quote::{format_ident, quote, quote_spanned}; |
5 | 5 | use syn::parse::{discouraged::Speculative, Parse, ParseStream}; |
| 6 | +use syn::GenericArgument; |
6 | 7 | use syn::{ |
7 | 8 | braced, punctuated::Punctuated, token::Brace, Data, DeriveInput, Error, Expr, ExprPath, Fields, |
8 | 9 | GenericParam, Generics, ItemStruct, LifetimeParam, Member, Path, Token, TraitBound, |
@@ -47,6 +48,23 @@ pub fn pin_init_derive(input: TokenStream) -> Result<TokenStream> { |
47 | 48 | } |
48 | 49 | }; |
49 | 50 |
|
| 51 | + let ty_generics: Vec<_> = generics |
| 52 | + .params |
| 53 | + .iter() |
| 54 | + .map(|x| match x { |
| 55 | + GenericParam::Lifetime(l) => GenericArgument::Lifetime(l.lifetime.clone()), |
| 56 | + GenericParam::Type(t) => GenericArgument::Type(syn::Type::Path(syn::TypePath { |
| 57 | + qself: None, |
| 58 | + path: Path::from(t.ident.clone()), |
| 59 | + })), |
| 60 | + GenericParam::Const(c) => GenericArgument::Const(syn::Expr::Path(ExprPath { |
| 61 | + attrs: Vec::new(), |
| 62 | + qself: None, |
| 63 | + path: Path::from(c.ident.clone()), |
| 64 | + })), |
| 65 | + }) |
| 66 | + .collect(); |
| 67 | + |
50 | 68 | let (mut fields, named) = match data.fields { |
51 | 69 | Fields::Named(v) => (v.named, true), |
52 | 70 | Fields::Unnamed(v) => (v.unnamed, false), |
@@ -113,16 +131,6 @@ pub fn pin_init_derive(input: TokenStream) -> Result<TokenStream> { |
113 | 131 | x |
114 | 132 | }) |
115 | 133 | .collect(); |
116 | | - let ty_generics: Vec<_> = generics |
117 | | - .iter() |
118 | | - .map(|x| -> &dyn ToTokens { |
119 | | - match x { |
120 | | - GenericParam::Lifetime(l) => &l.lifetime, |
121 | | - GenericParam::Type(t) => &t.ident, |
122 | | - GenericParam::Const(c) => &c.ident, |
123 | | - } |
124 | | - }) |
125 | | - .collect(); |
126 | 134 |
|
127 | 135 | // Create identifier names that are unlikely to be used. |
128 | 136 | let typestate_name: Vec<_> = field_name |
|
0 commit comments