a935064fae
Compiler: Rename "object safe" to "dyn compatible" Completed T-lang FCP: https://github.com/rust-lang/lang-team/issues/286#issuecomment-2338905118. Tracking issue: https://github.com/rust-lang/rust/issues/130852 Excludes `compiler/rustc_codegen_cranelift` (to be filed separately). Includes Stable MIR. Regarding https://github.com/rust-lang/rust/labels/relnotes, I guess I will manually open a https://github.com/rust-lang/rust/labels/relnotes-tracking-issue since this change affects everything (compiler, library, tools, docs, books, everyday language). r? ghost
78 lines
3.2 KiB
Plaintext
78 lines
3.2 KiB
Plaintext
error[E0038]: the trait `Trait` cannot be made into an object
|
|
--> $DIR/object-unsafe-trait-references-self.rs:9:12
|
|
|
|
|
LL | fn bar(x: &dyn Trait) {}
|
|
| ^^^^^^^^^ `Trait` cannot be made into an object
|
|
|
|
|
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>
|
|
--> $DIR/object-unsafe-trait-references-self.rs:2:22
|
|
|
|
|
LL | trait Trait {
|
|
| ----- this trait cannot be made into an object...
|
|
LL | fn baz(&self, _: Self) {}
|
|
| ^^^^ ...because method `baz` references the `Self` type in this parameter
|
|
LL |
|
|
LL | fn bat(&self) -> Self {}
|
|
| ^^^^ ...because method `bat` references the `Self` type in its return type
|
|
= help: consider moving `baz` to another trait
|
|
= help: consider moving `bat` to another trait
|
|
|
|
error[E0038]: the trait `Other` cannot be made into an object
|
|
--> $DIR/object-unsafe-trait-references-self.rs:13:12
|
|
|
|
|
LL | fn foo(x: &dyn Other) {}
|
|
| ^^^^^^^^^ `Other` cannot be made into an object
|
|
|
|
|
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>
|
|
--> $DIR/object-unsafe-trait-references-self.rs:11:14
|
|
|
|
|
LL | trait Other: Sized {}
|
|
| ----- ^^^^^ ...because it requires `Self: Sized`
|
|
| |
|
|
| this trait cannot be made into an object...
|
|
|
|
error[E0277]: the size for values of type `Self` cannot be known at compilation time
|
|
--> $DIR/object-unsafe-trait-references-self.rs:2:22
|
|
|
|
|
LL | fn baz(&self, _: Self) {}
|
|
| ^^^^ doesn't have a size known at compile-time
|
|
|
|
|
= help: unsized fn params are gated as an unstable feature
|
|
help: consider further restricting `Self`
|
|
|
|
|
LL | fn baz(&self, _: Self) where Self: Sized {}
|
|
| +++++++++++++++++
|
|
help: function arguments must have a statically known size, borrowed types always have a known size
|
|
|
|
|
LL | fn baz(&self, _: &Self) {}
|
|
| +
|
|
|
|
error[E0308]: mismatched types
|
|
--> $DIR/object-unsafe-trait-references-self.rs:4:27
|
|
|
|
|
LL | trait Trait {
|
|
| ----------- expected this type parameter
|
|
...
|
|
LL | fn bat(&self) -> Self {}
|
|
| ^^ expected type parameter `Self`, found `()`
|
|
|
|
|
= note: expected type parameter `Self`
|
|
found unit type `()`
|
|
|
|
error[E0277]: the size for values of type `Self` cannot be known at compilation time
|
|
--> $DIR/object-unsafe-trait-references-self.rs:4:22
|
|
|
|
|
LL | fn bat(&self) -> Self {}
|
|
| ^^^^ doesn't have a size known at compile-time
|
|
|
|
|
= note: the return type of a function must have a statically known size
|
|
help: consider further restricting `Self`
|
|
|
|
|
LL | fn bat(&self) -> Self where Self: Sized {}
|
|
| +++++++++++++++++
|
|
|
|
error: aborting due to 5 previous errors
|
|
|
|
Some errors have detailed explanations: E0038, E0277, E0308.
|
|
For more information about an error, try `rustc --explain E0038`.
|