2024-11-20 14:19:36 -08:00
|
|
|
error[E0038]: the trait `DynIncompatible` is not dyn compatible
|
2024-10-09 23:31:01 +02:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:22:13
|
2020-01-15 15:49:54 -08:00
|
|
|
|
|
2024-10-09 23:31:01 +02:00
|
|
|
LL | fn car() -> dyn DynIncompatible {
|
2024-11-20 14:19:36 -08:00
|
|
|
| ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` is not dyn compatible
|
2020-10-15 17:23:45 -07:00
|
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
note: for a trait to be dyn compatible it needs to allow building a vtable
|
2025-01-22 05:14:07 +01:00
|
|
|
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
|
2024-10-09 23:31:01 +02:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8
|
2020-10-15 17:23:45 -07:00
|
|
|
|
|
2024-10-09 23:31:01 +02:00
|
|
|
LL | trait DynIncompatible {
|
2024-11-20 14:19:36 -08:00
|
|
|
| --------------- this trait is not dyn compatible...
|
2020-01-15 15:49:54 -08:00
|
|
|
LL | fn foo() -> Self;
|
2020-10-15 17:23:45 -07:00
|
|
|
| ^^^ ...because associated function `foo` has no `self` parameter
|
2024-11-20 14:19:36 -08:00
|
|
|
= help: the following types implement `DynIncompatible`:
|
2023-10-24 16:45:04 +00:00
|
|
|
A
|
|
|
|
B
|
2024-11-20 14:19:36 -08:00
|
|
|
consider defining an enum where each variant holds one of these types,
|
|
|
|
implementing `DynIncompatible` for this new enum and using it instead
|
2020-10-15 17:23:45 -07:00
|
|
|
help: consider turning `foo` into a method by giving it a `&self` argument
|
2020-01-31 16:47:00 -08:00
|
|
|
|
|
2020-10-15 17:23:45 -07:00
|
|
|
LL | fn foo(&self) -> Self;
|
2021-06-21 19:07:19 -07:00
|
|
|
| +++++
|
2020-10-15 17:23:45 -07:00
|
|
|
help: alternatively, consider constraining `foo` so it does not apply to trait objects
|
2020-01-31 18:48:35 -08:00
|
|
|
|
|
|
|
|
LL | fn foo() -> Self where Self: Sized;
|
2021-06-21 19:07:19 -07:00
|
|
|
| +++++++++++++++++
|
2020-01-15 15:49:54 -08:00
|
|
|
|
2025-02-02 14:58:12 +00:00
|
|
|
error[E0746]: return type cannot be a trait object without pointer indirection
|
2025-01-30 04:23:14 +00:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:22:13
|
|
|
|
|
|
|
|
|
LL | fn car() -> dyn DynIncompatible {
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
|
|
|
|
|
|
|
|
help: consider returning an `impl Trait` instead of a `dyn Trait`
|
|
|
|
|
|
2024-07-09 22:30:26 +00:00
|
|
|
LL - fn car() -> dyn DynIncompatible {
|
|
|
|
LL + fn car() -> impl DynIncompatible {
|
|
|
|
|
|
2025-01-30 04:23:14 +00:00
|
|
|
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
|
|
|
|
|
|
|
|
|
LL ~ fn car() -> Box<dyn DynIncompatible> {
|
|
|
|
LL |
|
|
|
|
LL | if true {
|
|
|
|
LL ~ return Box::new(A);
|
|
|
|
LL | }
|
|
|
|
LL ~ Box::new(B)
|
|
|
|
|
|
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
error[E0038]: the trait `DynIncompatible` is not dyn compatible
|
2024-10-09 23:31:01 +02:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:30:17
|
2020-01-15 15:49:54 -08:00
|
|
|
|
|
2024-10-09 23:31:01 +02:00
|
|
|
LL | fn cat() -> Box<dyn DynIncompatible> {
|
2024-11-20 14:19:36 -08:00
|
|
|
| ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` is not dyn compatible
|
2020-10-15 17:23:45 -07:00
|
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
note: for a trait to be dyn compatible it needs to allow building a vtable
|
2025-01-22 05:14:07 +01:00
|
|
|
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
|
2024-10-09 23:31:01 +02:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8
|
2020-10-15 17:23:45 -07:00
|
|
|
|
|
2024-10-09 23:31:01 +02:00
|
|
|
LL | trait DynIncompatible {
|
2024-11-20 14:19:36 -08:00
|
|
|
| --------------- this trait is not dyn compatible...
|
2020-01-15 15:49:54 -08:00
|
|
|
LL | fn foo() -> Self;
|
2020-10-15 17:23:45 -07:00
|
|
|
| ^^^ ...because associated function `foo` has no `self` parameter
|
2024-11-20 14:19:36 -08:00
|
|
|
= help: the following types implement `DynIncompatible`:
|
2023-10-24 16:45:04 +00:00
|
|
|
A
|
|
|
|
B
|
2024-11-20 14:19:36 -08:00
|
|
|
consider defining an enum where each variant holds one of these types,
|
|
|
|
implementing `DynIncompatible` for this new enum and using it instead
|
2020-10-15 17:23:45 -07:00
|
|
|
help: consider turning `foo` into a method by giving it a `&self` argument
|
2020-01-31 16:47:00 -08:00
|
|
|
|
|
2020-10-15 17:23:45 -07:00
|
|
|
LL | fn foo(&self) -> Self;
|
2021-06-21 19:07:19 -07:00
|
|
|
| +++++
|
2020-10-15 17:23:45 -07:00
|
|
|
help: alternatively, consider constraining `foo` so it does not apply to trait objects
|
2020-01-31 18:48:35 -08:00
|
|
|
|
|
|
|
|
LL | fn foo() -> Self where Self: Sized;
|
2021-06-21 19:07:19 -07:00
|
|
|
| +++++++++++++++++
|
2020-01-15 15:49:54 -08:00
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
error[E0038]: the trait `DynIncompatible` is not dyn compatible
|
2024-10-09 23:31:01 +02:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:32:16
|
2024-02-09 12:17:55 +00:00
|
|
|
|
|
|
|
|
LL | return Box::new(A);
|
2024-11-20 14:19:36 -08:00
|
|
|
| ^^^^^^^^^^^ `DynIncompatible` is not dyn compatible
|
2024-02-09 12:17:55 +00:00
|
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
note: for a trait to be dyn compatible it needs to allow building a vtable
|
2025-01-22 05:14:07 +01:00
|
|
|
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
|
2024-10-09 23:31:01 +02:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8
|
2024-02-09 12:17:55 +00:00
|
|
|
|
|
2024-10-09 23:31:01 +02:00
|
|
|
LL | trait DynIncompatible {
|
2024-11-20 14:19:36 -08:00
|
|
|
| --------------- this trait is not dyn compatible...
|
2024-02-09 12:17:55 +00:00
|
|
|
LL | fn foo() -> Self;
|
|
|
|
| ^^^ ...because associated function `foo` has no `self` parameter
|
2024-11-20 14:19:36 -08:00
|
|
|
= help: the following types implement `DynIncompatible`:
|
2024-02-09 12:17:55 +00:00
|
|
|
A
|
|
|
|
B
|
2024-11-20 14:19:36 -08:00
|
|
|
consider defining an enum where each variant holds one of these types,
|
|
|
|
implementing `DynIncompatible` for this new enum and using it instead
|
2024-10-09 23:31:01 +02:00
|
|
|
= note: required for the cast from `Box<A>` to `Box<(dyn DynIncompatible + 'static)>`
|
2024-02-09 12:17:55 +00:00
|
|
|
help: consider turning `foo` into a method by giving it a `&self` argument
|
|
|
|
|
|
|
|
|
LL | fn foo(&self) -> Self;
|
|
|
|
| +++++
|
|
|
|
help: alternatively, consider constraining `foo` so it does not apply to trait objects
|
|
|
|
|
|
|
|
|
LL | fn foo() -> Self where Self: Sized;
|
|
|
|
| +++++++++++++++++
|
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
error[E0038]: the trait `DynIncompatible` is not dyn compatible
|
2024-10-09 23:31:01 +02:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:34:5
|
2024-02-09 12:17:55 +00:00
|
|
|
|
|
|
|
|
LL | Box::new(B)
|
2024-11-20 14:19:36 -08:00
|
|
|
| ^^^^^^^^^^^ `DynIncompatible` is not dyn compatible
|
2024-02-09 12:17:55 +00:00
|
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
note: for a trait to be dyn compatible it needs to allow building a vtable
|
2025-01-22 05:14:07 +01:00
|
|
|
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
|
2024-10-09 23:31:01 +02:00
|
|
|
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8
|
2024-02-09 12:17:55 +00:00
|
|
|
|
|
2024-10-09 23:31:01 +02:00
|
|
|
LL | trait DynIncompatible {
|
2024-11-20 14:19:36 -08:00
|
|
|
| --------------- this trait is not dyn compatible...
|
2024-02-09 12:17:55 +00:00
|
|
|
LL | fn foo() -> Self;
|
|
|
|
| ^^^ ...because associated function `foo` has no `self` parameter
|
2024-11-20 14:19:36 -08:00
|
|
|
= help: the following types implement `DynIncompatible`:
|
2024-02-09 12:17:55 +00:00
|
|
|
A
|
|
|
|
B
|
2024-11-20 14:19:36 -08:00
|
|
|
consider defining an enum where each variant holds one of these types,
|
|
|
|
implementing `DynIncompatible` for this new enum and using it instead
|
2024-10-09 23:31:01 +02:00
|
|
|
= note: required for the cast from `Box<B>` to `Box<(dyn DynIncompatible + 'static)>`
|
2024-02-09 12:17:55 +00:00
|
|
|
help: consider turning `foo` into a method by giving it a `&self` argument
|
|
|
|
|
|
|
|
|
LL | fn foo(&self) -> Self;
|
|
|
|
| +++++
|
|
|
|
help: alternatively, consider constraining `foo` so it does not apply to trait objects
|
|
|
|
|
|
|
|
|
LL | fn foo() -> Self where Self: Sized;
|
|
|
|
| +++++++++++++++++
|
|
|
|
|
|
|
|
error: aborting due to 5 previous errors
|
2020-01-15 15:49:54 -08:00
|
|
|
|
2024-02-09 12:17:55 +00:00
|
|
|
Some errors have detailed explanations: E0038, E0746.
|
|
|
|
For more information about an error, try `rustc --explain E0038`.
|