Skip to content

Commit 7a71418

Browse files
JakobDegenfacebook-github-bot
authored andcommitted
module: Remove useless lifetime inference code
Summary: This tries to figure out exactly what lifetime generics are needed. But there's only one lifetime ever in scope, `'v`, and we can just always add that Reviewed By: ndmitchell Differential Revision: D73726015 fbshipit-source-id: 1bf2529a951c135f76b1444e74ed26c1e9cd8018
1 parent cfecbd5 commit 7a71418

File tree

1 file changed

+1
-67
lines changed

1 file changed

+1
-67
lines changed

starlark_derive/src/module/render.rs

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
mod fun;
1919

20-
use std::collections::HashSet;
21-
2220
use proc_macro2::TokenStream;
2321
use quote::ToTokens;
2422
use quote::format_ident;
@@ -168,75 +166,11 @@ fn render_attr(x: StarAttr) -> syn::Stmt {
168166
}
169167
}
170168

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-
234169
pub(crate) fn render_starlark_type(typ: &syn::Type) -> syn::Expr {
235-
let lifetimes = get_lifetimes(typ);
236170
syn::parse_quote! {
237171
{
238172
#[allow(clippy::extra_unused_lifetimes)]
239-
fn get_type_string #lifetimes() -> starlark::typing::Ty {
173+
fn get_type_string<'v>() -> starlark::typing::Ty {
240174
<#typ as starlark::values::type_repr::StarlarkTypeRepr>::starlark_type_repr()
241175
}
242176
get_type_string()

0 commit comments

Comments
 (0)