rust/tests/ui/suggestions/object-unsafe-trait-should-use-self-2021-without-dyn.stderr

177 lines
6.7 KiB
Plaintext

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
LL | fn f(b: B) -> B;
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(b: Self) -> Self;
| ~~~~ ~~~~
error[E0038]: the trait `B` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13
|
LL | fn f(b: B) -> B;
| ^ `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...
LL | fn f(b: B) -> 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, b: B) -> B;
| ++++++
help: alternatively, consider constraining `f` so it does not apply to trait objects
|
LL | fn f(b: B) -> B where Self: Sized;
| +++++++++++++++++
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
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;
| ^
|
= note: `A` it is not object safe, so it can't be `dyn`
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;
| ^
|
help: `A` is not object safe, use `impl A` to return an opaque type, as long as you return a single underlying type
|
LL | fn f(a: A) -> impl A;
| ++++
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13
|
LL | fn f(b: B) -> B;
| ^
|
= note: `B` it is not object safe, so it can't be `dyn`
help: use a new generic type parameter, constrained by `B`
|
LL | fn f<T: B>(b: T) -> B;
| ++++++ ~
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(b: impl B) -> B;
| ++++
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:19
|
LL | fn f(b: B) -> B;
| ^
|
help: `B` is not object safe, use `impl B` to return an opaque type, as long as you return a single underlying type
|
LL | fn f(b: B) -> impl B;
| ++++
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20
|
LL | fn f(&self, c: C) -> C;
| ^
|
= note: `C` it is not object safe, so it can't be `dyn`
help: use a new generic type parameter, constrained by `C`
|
LL | fn f<T: C>(&self, c: T) -> C;
| ++++++ ~
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(&self, c: impl C) -> C;
| ++++
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:26
|
LL | fn f(&self, c: C) -> C;
| ^
|
help: `C` is not object safe, use `impl C` to return an opaque type, as long as you return a single underlying type
|
LL | fn f(&self, c: C) -> impl C;
| ++++
error: aborting due to 12 previous errors
Some errors have detailed explanations: E0038, E0782.
For more information about an error, try `rustc --explain E0038`.