|
17 | 17 |
|
18 | 18 | mod fun;
|
19 | 19 |
|
20 |
| -use std::collections::HashSet; |
21 |
| - |
22 | 20 | use proc_macro2::TokenStream;
|
23 | 21 | use quote::ToTokens;
|
24 | 22 | use quote::format_ident;
|
@@ -168,75 +166,11 @@ fn render_attr(x: StarAttr) -> syn::Stmt {
|
168 | 166 | }
|
169 | 167 | }
|
170 | 168 |
|
171 |
| -/// Get the lifetimes that are mentioned in a given type and its nested generics. |
172 |
| -fn get_lifetimes_inner<'a>(ret: &mut HashSet<&'a syn::Lifetime>, typ: &'a syn::Type) { |
173 |
| - match typ { |
174 |
| - syn::Type::Path(path) => { |
175 |
| - if let Some(segment) = path.path.segments.last() { |
176 |
| - match &segment.arguments { |
177 |
| - syn::PathArguments::None => {} |
178 |
| - syn::PathArguments::AngleBracketed(args) => { |
179 |
| - for arg in &args.args { |
180 |
| - match arg { |
181 |
| - syn::GenericArgument::Lifetime(l) => { |
182 |
| - ret.insert(l); |
183 |
| - } |
184 |
| - syn::GenericArgument::Type(t) => get_lifetimes_inner(ret, t), |
185 |
| - _ => {} |
186 |
| - }; |
187 |
| - } |
188 |
| - } |
189 |
| - syn::PathArguments::Parenthesized(args) => { |
190 |
| - for t in &args.inputs { |
191 |
| - get_lifetimes_inner(ret, t); |
192 |
| - } |
193 |
| - match &args.output { |
194 |
| - syn::ReturnType::Default => {} |
195 |
| - syn::ReturnType::Type(_, t) => get_lifetimes_inner(ret, t), |
196 |
| - }; |
197 |
| - } |
198 |
| - }; |
199 |
| - } |
200 |
| - } |
201 |
| - syn::Type::Group(g) => get_lifetimes_inner(ret, &g.elem), |
202 |
| - syn::Type::Paren(p) => get_lifetimes_inner(ret, &p.elem), |
203 |
| - syn::Type::Ptr(p) => get_lifetimes_inner(ret, &p.elem), |
204 |
| - syn::Type::Reference(r) => { |
205 |
| - if let Some(l) = &r.lifetime { |
206 |
| - ret.insert(l); |
207 |
| - }; |
208 |
| - get_lifetimes_inner(ret, &r.elem); |
209 |
| - } |
210 |
| - syn::Type::Tuple(t) => { |
211 |
| - for t in &t.elems { |
212 |
| - get_lifetimes_inner(ret, t); |
213 |
| - } |
214 |
| - } |
215 |
| - _ => {} |
216 |
| - }; |
217 |
| -} |
218 |
| - |
219 |
| -/// Get the lifetime specifications to use with a function based on the lifetimes mentioned in `typ`. |
220 |
| -/// |
221 |
| -/// e.g. `i32` would return ``, `Vec<(&'a str, &'b str)>` would return `<'a, 'b>` |
222 |
| -fn get_lifetimes(typ: &syn::Type) -> TokenStream { |
223 |
| - let mut ret = HashSet::new(); |
224 |
| - get_lifetimes_inner(&mut ret, typ); |
225 |
| - if ret.is_empty() { |
226 |
| - TokenStream::new() |
227 |
| - } else { |
228 |
| - let mut ret: Vec<_> = ret.into_iter().filter(|l| l.ident != "_").collect(); |
229 |
| - ret.sort_by(|l, r| l.ident.cmp(&r.ident)); |
230 |
| - quote!(<#(#ret),*>) |
231 |
| - } |
232 |
| -} |
233 |
| - |
234 | 169 | pub(crate) fn render_starlark_type(typ: &syn::Type) -> syn::Expr {
|
235 |
| - let lifetimes = get_lifetimes(typ); |
236 | 170 | syn::parse_quote! {
|
237 | 171 | {
|
238 | 172 | #[allow(clippy::extra_unused_lifetimes)]
|
239 |
| - fn get_type_string #lifetimes() -> starlark::typing::Ty { |
| 173 | + fn get_type_string<'v>() -> starlark::typing::Ty { |
240 | 174 | <#typ as starlark::values::type_repr::StarlarkTypeRepr>::starlark_type_repr()
|
241 | 175 | }
|
242 | 176 | get_type_string()
|
|
0 commit comments