2024-01-19 17:49:40 -06:00
error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13
|
LL | trait A: Sized {
| - in this trait
LL | fn f(a: A) -> 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
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13
|
LL | fn f(a: A) -> A;
| ^ `A` cannot be made into an object
|
note: for a trait to be "object safe" 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>
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:3:10
|
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
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13
|
LL | trait B {
| - in this trait
2024-01-20 10:12:54 -06:00
LL | fn f(b: B) -> B;
2024-01-19 17:49:40 -06:00
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
2024-01-20 10:12:54 -06:00
LL | fn f(b: Self) -> Self;
2024-01-19 17:49:40 -06:00
| ~~~~ ~~~~
error[E0038]: the trait `B` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13
|
2024-01-20 10:12:54 -06:00
LL | fn f(b: B) -> B;
2024-01-19 17:49:40 -06:00
| ^ `B` cannot be made into an object
|
note: for a trait to be "object safe" 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>
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:8
|
LL | trait B {
| - this trait cannot be made into an object...
2024-01-20 10:12:54 -06:00
LL | fn f(b: B) -> B;
2024-01-19 17:49:40 -06:00
| ^ ...because associated function `f` has no `self` parameter
help: consider turning `f` into a method by giving it a `&self` argument
|
2024-01-20 10:12:54 -06:00
LL | fn f(&self, b: B) -> B;
2024-01-19 17:49:40 -06:00
| ++++++
help: alternatively, consider constraining `f` so it does not apply to trait objects
|
2024-01-20 10:12:54 -06:00
LL | fn f(b: B) -> B where Self: Sized;
2024-01-19 17:49:40 -06:00
| +++++++++++++++++
2024-01-20 10:12:54 -06:00
error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20
|
LL | trait C {
| - in this trait
LL | fn f(&self, c: C) -> C;
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(&self, c: Self) -> Self;
| ~~~~ ~~~~
error[E0038]: the trait `C` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20
|
LL | fn f(&self, c: C) -> C;
| ----- ^ `C` cannot be made into an object
| |
| help: consider changing method `f`'s `self` parameter to be `&self` (notice the capitalization): `&Self`
|
note: for a trait to be "object safe" 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>
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:10
|
LL | trait C {
| - this trait cannot be made into an object...
LL | fn f(&self, c: C) -> C;
| ^^^^^ ...because method `f`'s `self` parameter cannot be dispatched on
2024-01-08 18:22:35 -06:00
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13
|
LL | fn f(a: A) -> A;
| ^
|
2024-01-20 10:12:54 -06:00
= note: `A` it is not object safe, so it can't be `dyn`
2024-01-08 18:22:35 -06:00
help: use a new generic type parameter, constrained by `A`
|
LL | fn f<T: A>(a: T) -> A;
| ++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
|
LL | fn f(a: impl A) -> A;
| ++++
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:19
|
LL | fn f(a: A) -> A;
| ^
|
2024-01-20 10:12:54 -06:00
help: `A` is not object safe, use `impl A` to return an opaque type, as long as you return a single underlying type
2024-01-08 18:22:35 -06:00
|
LL | fn f(a: A) -> impl A;
| ++++
error[E0782]: trait objects must include the `dyn` keyword
2024-01-19 17:49:40 -06:00
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13
2024-01-08 18:22:35 -06:00
|
2024-01-20 10:12:54 -06:00
LL | fn f(b: B) -> B;
2024-01-08 18:22:35 -06:00
| ^
|
2024-01-20 10:12:54 -06:00
= note: `B` it is not object safe, so it can't be `dyn`
2024-01-08 18:22:35 -06:00
help: use a new generic type parameter, constrained by `B`
|
2024-01-20 10:12:54 -06:00
LL | fn f<T: B>(b: T) -> B;
2024-01-08 18:22:35 -06:00
| ++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
|
2024-01-20 10:12:54 -06:00
LL | fn f(b: impl B) -> B;
2024-01-08 18:22:35 -06:00
| ++++
error[E0782]: trait objects must include the `dyn` keyword
2024-01-19 17:49:40 -06:00
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:19
2024-01-08 18:22:35 -06:00
|
2024-01-20 10:12:54 -06:00
LL | fn f(b: B) -> B;
2024-01-08 18:22:35 -06:00
| ^
|
2024-01-20 10:12:54 -06:00
help: `B` is not object safe, use `impl B` to return an opaque type, as long as you return a single underlying type
2024-01-08 18:22:35 -06:00
|
2024-01-20 10:12:54 -06:00
LL | fn f(b: B) -> impl B;
2024-01-08 18:22:35 -06:00
| ++++
error[E0782]: trait objects must include the `dyn` keyword
2024-01-19 17:49:40 -06:00
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20
2024-01-08 18:22:35 -06:00
|
2024-01-20 10:12:54 -06:00
LL | fn f(&self, c: C) -> C;
2024-01-08 18:22:35 -06:00
| ^
|
2024-01-20 10:12:54 -06:00
= note: `C` it is not object safe, so it can't be `dyn`
2024-01-08 18:22:35 -06:00
help: use a new generic type parameter, constrained by `C`
|
2024-01-20 10:12:54 -06:00
LL | fn f<T: C>(&self, c: T) -> C;
2024-01-08 18:22:35 -06:00
| ++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
|
2024-01-20 10:12:54 -06:00
LL | fn f(&self, c: impl C) -> C;
2024-01-08 18:22:35 -06:00
| ++++
error[E0782]: trait objects must include the `dyn` keyword
2024-01-19 17:49:40 -06:00
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:26
2024-01-08 18:22:35 -06:00
|
2024-01-20 10:12:54 -06:00
LL | fn f(&self, c: C) -> C;
2024-01-08 18:22:35 -06:00
| ^
|
2024-01-20 10:12:54 -06:00
help: `C` is not object safe, use `impl C` to return an opaque type, as long as you return a single underlying type
2024-01-08 18:22:35 -06:00
|
2024-01-20 10:12:54 -06:00
LL | fn f(&self, c: C) -> impl C;
2024-01-08 18:22:35 -06:00
| ++++
2024-01-20 10:12:54 -06:00
error: aborting due to 12 previous errors
2024-01-08 18:22:35 -06:00
2024-01-19 17:49:40 -06:00
Some errors have detailed explanations: E0038, E0782.
For more information about an error, try `rustc --explain E0038`.