Skip to content

Commit

Permalink
#98 Forgot unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
la10736 committed May 2, 2021
1 parent f388dc5 commit 3106354
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/parse/future.rs
Expand Up @@ -14,10 +14,18 @@ impl ReplaceFutureAttribute {
let mut visitor = Self::default();
visitor.visit_item_fn_mut(item_fn);
if !visitor.lifetimes.is_empty() {
let all = visitor.lifetimes
.iter()
.map(|lt| lt as &dyn ToTokens)
.chain(item_fn.sig.generics.params.iter().map(|gp| gp as &dyn ToTokens));
let all = visitor
.lifetimes
.iter()
.map(|lt| lt as &dyn ToTokens)
.chain(
item_fn
.sig
.generics
.params
.iter()
.map(|gp| gp as &dyn ToTokens),
);
item_fn.sig.generics = parse_quote! {
<#(#all),*>
};
Expand All @@ -30,17 +38,19 @@ impl ReplaceFutureAttribute {
}
}

fn extract_arg_attributes(node: &mut syn::PatType, predicate: fn(a: &syn::Attribute) -> bool) -> Vec<syn::Attribute> {
fn extract_arg_attributes(
node: &mut syn::PatType,
predicate: fn(a: &syn::Attribute) -> bool,
) -> Vec<syn::Attribute> {
let attrs = std::mem::take(&mut node.attrs);
let (extracted, attrs): (Vec<_>, Vec<_>) =
attrs.into_iter().partition(predicate);
let (extracted, attrs): (Vec<_>, Vec<_>) = attrs.into_iter().partition(predicate);
node.attrs = attrs;
extracted
}

impl VisitMut for ReplaceFutureAttribute {
fn visit_fn_arg_mut(&mut self, node: &mut FnArg) {
let ident = node.maybe_ident().cloned().unwrap();
let ident = node.maybe_ident().cloned();
match node {
FnArg::Typed(t) => {
let futures = extract_arg_attributes(t, |a| attr_is(a, "future"));
Expand Down Expand Up @@ -69,6 +79,7 @@ impl VisitMut for ReplaceFutureAttribute {
_ => {}
};
if let Reference(tr) = ty.as_mut() {
let ident = ident.unwrap();
if tr.lifetime.is_none() {
let lifetime = syn::Lifetime {
apostrophe: ident.span(),
Expand Down

0 comments on commit 3106354

Please sign in to comment.