Open
Description
A simplified example where this shows up is the following trait.
trait Conversion {
type Source: Into<Self::Target>;
type Target;
}
If you try to make a trait object, say &dyn Conversion<Source = String, Target = Box<str>>
, then Rust errors:
error[E0038]: the trait `Conversion` cannot be made into an object
--> src/main.rs:14:12
|
1 | trait Conversion {
| ---------- this trait cannot be made into an object...
2 | type Source: Into<Self::Target>;
| ------------------ ...because it uses `Self` as a type parameter in this
...
14 | let b: &dyn Conversion<Source = String, Target = Box<str>> = &a;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Conversion` cannot be made into an object
If the bound was something like Source: Into<Self>
this error would make sense, but instead the bound references another associated type, which all must be fully specified when making a trait object type anyway.
This problem does not seem to occur when associated types are used to define functions in the trait, as creating a &dyn Deref<Target = ...>
trait object works.
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Dyn compatibility (formerly: object safety)Area: trait objects, vtable layoutArea: Trait systemCategory: This is a bug.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.