Skip to content

Add error explanation for E0038 #26163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,33 @@ This error indicates that an attempt was made to divide by zero (or take the
remainder of a zero divisor) in a static or constant expression.
"##,

E0038: r##"
It is not allowed to create a trait object value for a trait that is not object
safe. Traits are object safe only if all these conditions are met:

- the trait does not have `Self: Sized` as a bound, to enforce the abstraction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using pseudo markdown in errors explanation (correct me if I'm wrong), list should start with '*' and not '-'.

of an unknown underlying implementation with potentially arbitrary size
("the trait cannot require that `Self : Sized`"),

- any supertrait predicates bounding the trait do not have `Self` ("the trait
cannot use `Self` as a type parameter in the supertrait listing"), and

- all methods defined by the trait have a receiver; methods must accept `self`
(or some variation thereof) as exactly the first argument, and stopping trait
objects from enforcing the existence of static methods ("method `...` has no
receiver"),

- no method defined references `Self` anywhere except on the receiver ("method
`...` references the `Self` type in its arguments or return type"), and

- no method defined has generic type parameters ("method `...` has generic type
parameters").

See [RFC 255] for more details on object safety for trait objects.

[RFC 255]: https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md
"##,

E0079: r##"
Enum variants which contain no data can be given a custom integer
representation. This error indicates that the value provided is not an
Expand Down Expand Up @@ -1204,7 +1231,6 @@ contain references (with a maximum lifetime of `'a`).
register_diagnostics! {
E0017,
E0022,
E0038,
// E0134,
// E0135,
E0136,
Expand Down