"one type is more general than the other" when trying to use .boxed() on future

In this example in my library s3-algo, if you remove this line it works fine:

with .boxed() there I get errors:

error[E0308]: mismatched types
  --> examples/simple.rs:19:6
   |
19 |     .boxed()
   |      ^^^^^ one type is more general than the other
   |
   = note: expected type `std::ops::FnOnce<(std::pin::Pin<std::boxed::Box<dyn core::future::future::Future<Output = std::result::Result<(f64, u64, std::time::Duration, std::time::Duration, usize), s3_algo::err::Error>> + std::marker::Send>>,)>`
              found type `std::ops::FnOnce<(std::pin::Pin<std::boxed::Box<dyn core::future::future::Future<Output = std::result::Result<(f64, u64, std::time::Duration, std::time::Duration, usize), s3_algo::err::Error>> + std::marker::Send>>,)>`

error[E0308]: mismatched types
  --> examples/simple.rs:19:6
   |
7  |       let files = (0..N_FILES).map(|i| ObjectSource::data(format!("hey, {}", i), format!("hey{}", i)));
   |                                    ------------------------------------------------------------------
   |                                    |
   |                                    one of the expected closures
   |                                    one of the found closures
...
13 | /         |result| {
14 | |             println!("File {}/{} successfully uploaded", result.seq+1, N_FILES);
15 | |             ok(())
16 | |         },
   | |         -
   | |         |
   | |_________one of the expected closures
   |           one of the found closures
...
19 |       .boxed()
   |        ^^^^^ one type is more general than the other
   |
  ::: /home/erlend/code/s3-algo/src/upload.rs:61:35
   |
61 |           .then(move |x| async move {
   |  ___________________________________-
   | |___________________________________|
   | |
62 | |             delay_for(Duration::from_secs(extra_copy_file_time_s)).await;
63 | |             x
64 | |         })
   | |         -
   | |_________|
   | |_________the expected generator
   |           the found generator
   |
   = note: expected opaque type `impl core::future::future::Future`
              found opaque type `impl core::future::future::Future`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `s3-algo`.

I know this has to do with lifetimes, but I have no idea how to solve it in this case.

We had another thread on this error not too long ago over here. Not that it got solved.

1 Like

Thanks. Is there any issue anywhere I can follow? Because I keep hitting this error in different parts of my code.

You can take a look at this issue, and also this and this. It seems to be related to constraints with for<'a> and those without it.

1 Like

See also this issue.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.