Skip to content

Commit 4f8b125

Browse files
committed
Add test for dyn Trait in async fn return type
1 parent 3025465 commit 4f8b125

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ edition:2024
2+
3+
async fn f() -> dyn core::fmt::Debug {
4+
//~^ ERROR return type cannot be a trait object without pointer indirection
5+
//~| HELP consider returning an `impl Trait` instead of a `dyn Trait`
6+
//~| HELP alternatively, box the return type, and wrap all of the returned values in `Box::new`
7+
loop {}
8+
}
9+
10+
fn main() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0746]: return type cannot be a trait object without pointer indirection
2+
--> $DIR/dyn-in-return-type.rs:3:38
3+
|
4+
LL | async fn f() -> dyn core::fmt::Debug {
5+
| ______________________________________^
6+
... |
7+
LL | | }
8+
| |_^ doesn't have a size known at compile-time
9+
|
10+
help: consider returning an `impl Trait` instead of a `dyn Trait`
11+
|
12+
LL | async fn f() -> dyn core::fmt::Debug impl {
13+
| ++++
14+
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
15+
|
16+
LL ~ async fn f() -> dyn core::fmt::Debug Box<dyn {
17+
LL |
18+
...
19+
LL | loop {}
20+
LL ~ }>
21+
|
22+
23+
error: aborting due to 1 previous error
24+
25+
For more information about this error, try `rustc --explain E0746`.

0 commit comments

Comments
 (0)