Skip to content

Commit 349f572

Browse files
committed
Add test for type Alias = dyn Trait in return type
1 parent 7f8a587 commit 349f572

File tree

2 files changed

+26
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)