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

Remove the return Box<dyn Trait> issue in async fn #88

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/07_workarounds/02_return_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,3 @@ function signature with the message "expected `SomeType`, found `OtherType`"
usually indicate that one or more return sites are incorrect.

A fix to this issue is being tracked in [this bug](https://github.com/rust-lang/rust/issues/54326).

## `Box<dyn Trait>`

Similarly, because the return type from the function signature is not
propagated down correctly, values returned from `async fn` aren't correctly
coerced to their expected type.

In practice, this means that returning `Box<dyn Trait>` objects from an
`async fn` requires manually `as`-casting from `Box<MyType>` to
`Box<dyn Trait>`.

This code will result in an error:

```rust,edition2018,ignore
async fn x() -> Box<dyn std::fmt::Display> {
Box::new("foo")
}
```

This issue can be worked around by manually casting using `as`:

```rust,edition2018
async fn x() -> Box<dyn std::fmt::Display> {
Box::new("foo") as Box<dyn std::fmt::Display>
}
```

A fix to this issue is being tracked in [this bug](https://github.com/rust-lang/rust/issues/60424).