-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
When a struct cannot be turned into a trait object due to a trait bound,
the compiler errors are very cryptic and unhelpful.
trait T: Clone {}
#[derive(Clone)]
struct S {}
fn main() {
let x: &T = & S{};
}
This results in the following errors (both on stable and nightly):
rustc 1.13.0 (2c6933acc 2016-11-07)
error[E0038]: the trait `T` cannot be made into an object
--> <anon>:12:15
|
12 | let x: &T = & S{};
| ^^^^^ the trait `T` cannot be made into an object
|
= note: the trait cannot require that `Self : Sized`
= note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&T>` for `&S`
error[E0038]: the trait `T` cannot be made into an object
--> <anon>:12:10
|
12 | let x: &T = & S{};
| ^^ the trait `T` cannot be made into an object
|
= note: the trait cannot require that `Self : Sized`
error: aborting due to 2 previous errors
The problem lies with the : Clone
trait bound, since Clone is not object safe.
But the errors do not mention Clone at all, which leaves someone relatively new to Rust (like me) completely stranded and puzzled as to what might be the problem.
Better errors here would be a big win.
My ideal error would be something like:
the trait 'T' cannot be made into an object.
...
note: T requires the trait bound 'Clone', which cannot be made into an object`.
wesleywiser, druerridge, lilith, m10s, Techno-coder and 13 more
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.