]> git.lizzy.rs Git - rust.git/commit
Implement the object-safety checks for arbitrary_self_types: part 1
authorMichael Hewson <michael@michaelhewson.ca>
Thu, 20 Sep 2018 07:12:00 +0000 (03:12 -0400)
committerMichael Hewson <michael@michaelhewson.ca>
Thu, 1 Nov 2018 22:15:19 +0000 (18:15 -0400)
commitd5c2c4a4339b2a6c64d16282d85bfd27bf01d361
tree0b24b58a863e34c40b83c8bbb151e792addfd991
parentbe80a79a1ea247a71e5ffa408356b9b72cddb644
Implement the object-safety checks for arbitrary_self_types: part 1

For a trait method to be considered object-safe, the receiver type must
satisfy certain properties: first, we need to be able to get the vtable
to so we can look up the method, and second, we need to convert the
receiver from the version where `Self=dyn Trait`, to the version where
`Self=T`, `T` being some unknown, `Sized` type that implements `Trait`.

To check that the receiver satisfies those properties, we use the
following query:

forall (U) {
if (Self: Unsize<U>) {
Receiver[Self => U]: CoerceSized<Receiver>
}
}

where `Receiver` is the receiver type of the method (e.g. `Rc<Self>`),
and `Receiver[Self => U]` is the receiver type where `Self = U`, e.g.
`Rc<U>`.

forall queries like this aren’t implemented in the trait system yet, so
for now we are using a bit of a hack — see the code for explanation.
src/librustc/traits/object_safety.rs