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

type inference doesn't work in async fn that return Box<dyn SomeTrait> #60424

macpp opened this issue Apr 30, 2019 · 1 comment


None yet
3 participants
Copy link

commented Apr 30, 2019

i have following fn that works completly fine:

pub fn test1() -> Box<dyn Debug> {

if i try trivialy make it async just by adding async keyword i get build error:

error[E0271]: type mismatch resolving `<impl core::future::future::Future as core::future::future::Future>::Output == std::boxed::Box<(dyn std::fmt::Debug + 'static)>`
  --> comix_downloader_lib_async/src/
49 | pub async fn test1() -> Box<dyn Debug> {
   |                         ^^^^^^^^^^^^^^ expected &str, found trait std::fmt::Debug
   = note: expected type `std::boxed::Box<&str>`
              found type `std::boxed::Box<(dyn std::fmt::Debug + 'static)>`
   = note: the return type of a function must have a statically known size

i can work around this by defining types of variables explicitly:

pub async fn test3() -> Box<dyn Debug> {
    let tmp : Box<dyn Debug> = Box::new("asdf");

but for obvious reasons this is not as nice as sync version
maybe related to #60414 ?

rustc --version : rustc 1.36.0-nightly (00859e3e6 2019-04-29)

@macpp macpp changed the title type inferance doesn't work in async fn that return Box<dyn SomeTrait> type inference doesn't work in async fn that return Box<dyn SomeTrait> Apr 30, 2019


This comment has been minimized.

Copy link

commented May 1, 2019

I'd put this under a similar camp as #54326 -- the issue here is that we need to fix the output of the Future to the return type as provided, rather than trying to infer it from the context (which isn't smart enough in this case to see that a trait object coercion is required).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.