Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

join_all() is too picky about lifetimes #285

Closed
dwrensha opened this issue Dec 11, 2016 · 5 comments
Closed

join_all() is too picky about lifetimes #285

dwrensha opened this issue Dec 11, 2016 · 5 comments

Comments

@dwrensha
Copy link
Contributor

Consider the following function:

fn foo<'a>(bufs: Vec<&'a [u8]>) -> Box<::futures::Future<Item=Vec<usize>, Error=()> + 'static> {
    let iter = bufs.into_iter().map(|b| ::futures::future::ok::<usize, ()>(b.len()));
    Box::new(::futures::future::join_all(iter))
}

I expect this to typecheck successfully, but I get an error:

error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
  --> src/main.rs:35:21
   |
35 |     let iter = bufs.into_iter().map(|b| ::futures::future::ok::<usize, ()>(b.len()));
   |                     ^^^^^^^^^
   |
   = note: first, the lifetime cannot outlive the lifetime 'a as defined on unknown free region bounded by scope CodeExtent(212/CallSiteScope { fn_id: NodeId(122), body_id: NodeId(276) })...
note: ...so that types are compatible (expected std::vec::Vec<&[u8]>, found std::vec::Vec<&'a [u8]>)
  --> src/main.rs:35:21
   |
35 |     let iter = bufs.into_iter().map(|b| ::futures::future::ok::<usize, ()>(b.len()));
   |                     ^^^^^^^^^
   = note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type `futures::JoinAll<std::iter::Map<std::vec::IntoIter<&[u8]>, [closure@src/main.rs:35:37: 35:84]>>` will meet its required lifetime bounds
  --> src/main.rs:36:5
   |
36 |     Box::new(::futures::future::join_all(iter))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

The problem seems to be that JoinAll<I> is parameterized by the type of the IntoIterator that is passed into join_all(). In the above case, that type is not 'static, even though its Item is 'static.

@carllerche
Copy link
Member

Is there an action item to take from this? The issue has been inactive for a year.

@stuhood
Copy link
Contributor

stuhood commented Dec 16, 2017

@carllerche : I believe this will be useful for 0.2, but requires changing the parameters of JoinAll see the linked PR and the other issue.

@alexcrichton
Copy link
Member

@carllerche the fix, a breaking change, is at #286 (linked above)

@stuhood
Copy link
Contributor

stuhood commented Feb 5, 2018

Both this and #286 should be closable now, as they've landed in the 0.2 branch.

@alexcrichton
Copy link
Member

Thanks @stuhood!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants