2024-01-08 18:22:35 -06:00
error: associated item referring to unboxed trait object for its own trait
2024-10-09 16:31:01 -05:00
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:4:13
2024-01-08 18:22:35 -06:00
|
LL | trait A: Sized {
| - in this trait
LL | fn f(a: dyn A) -> dyn A;
| ^^^^^ ^^^^^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~
error[E0038]: the trait `A` cannot be made into an object
2024-10-09 16:31:01 -05:00
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:4:13
2024-01-08 18:22:35 -06:00
|
LL | fn f(a: dyn A) -> dyn A;
| ^^^^^ `A` cannot be made into an object
|
2024-09-25 03:38:40 -05:00
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
2024-10-09 16:31:01 -05:00
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:3:10
2024-01-08 18:22:35 -06:00
|
LL | trait A: Sized {
| - ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
error: associated item referring to unboxed trait object for its own trait
2024-10-09 16:31:01 -05:00
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:13
2024-01-08 18:22:35 -06:00
|
LL | trait B {
| - in this trait
LL | fn f(a: dyn B) -> dyn B;
| ^^^^^ ^^^^^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~
error[E0038]: the trait `B` cannot be made into an object
2024-10-09 16:31:01 -05:00
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:13
2024-01-08 18:22:35 -06:00
|
LL | fn f(a: dyn B) -> dyn B;
| ^^^^^ `B` cannot be made into an object
|
2024-09-25 03:38:40 -05:00
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
2024-10-09 16:31:01 -05:00
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:8
2024-01-08 18:22:35 -06:00
|
LL | trait B {
| - this trait cannot be made into an object...
LL | fn f(a: dyn B) -> dyn B;
| ^ ...because associated function `f` has no `self` parameter
help: consider turning `f` into a method by giving it a `&self` argument
|
LL | fn f(&self, a: dyn B) -> dyn B;
| ++++++
help: alternatively, consider constraining `f` so it does not apply to trait objects
|
LL | fn f(a: dyn B) -> dyn B where Self: Sized;
| +++++++++++++++++
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0038`.