Skip to content

Commit bb89034

Browse files
author
Jesse Wang
authored
Remove the return Box<dyn Trait> issue
The bug has been fixed at rust-lang/rust#60424.
1 parent d073a9d commit bb89034

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

src/07_workarounds/02_return_type.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,3 @@ function signature with the message "expected `SomeType`, found `OtherType`"
4242
usually indicate that one or more return sites are incorrect.
4343

4444
A fix to this issue is being tracked in [this bug](https://github.com/rust-lang/rust/issues/54326).
45-
46-
## `Box<dyn Trait>`
47-
48-
Similarly, because the return type from the function signature is not
49-
propagated down correctly, values returned from `async fn` aren't correctly
50-
coerced to their expected type.
51-
52-
In practice, this means that returning `Box<dyn Trait>` objects from an
53-
`async fn` requires manually `as`-casting from `Box<MyType>` to
54-
`Box<dyn Trait>`.
55-
56-
This code will result in an error:
57-
58-
```rust,edition2018,ignore
59-
async fn x() -> Box<dyn std::fmt::Display> {
60-
Box::new("foo")
61-
}
62-
```
63-
64-
This issue can be worked around by manually casting using `as`:
65-
66-
```rust,edition2018
67-
async fn x() -> Box<dyn std::fmt::Display> {
68-
Box::new("foo") as Box<dyn std::fmt::Display>
69-
}
70-
```
71-
72-
A fix to this issue is being tracked in [this bug](https://github.com/rust-lang/rust/issues/60424).

0 commit comments

Comments
 (0)