Commit 297850a
committed
Add more checks for pointers with vtable meta
The rules for casting `*mut X<dyn A>` -> `*mut Y<dyn B>` are as follows:
- If `B` has a principal
- `A` must have exactly the same principal (including generics)
- Auto traits of `B` must be a subset of autotraits in `A`
Note that `X<_>` and `Y<_>` can be identity, or arbitrary structs with last field being the dyn type.
The lifetime of the trait object itself (`dyn ... + 'a`) is not checked.
This prevents a few soundness issues with `#![feature(arbitrary_self_types)]` and trait upcasting.
Namely, these checks make sure that vtable is always valid for the pointee.1 parent de4f5c2 commit 297850a
1 file changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2374 | 2374 | | |
2375 | 2375 | | |
2376 | 2376 | | |
2377 | | - | |
| 2377 | + | |
2378 | 2378 | | |
2379 | 2379 | | |
2380 | 2380 | | |
| |||
2387 | 2387 | | |
2388 | 2388 | | |
2389 | 2389 | | |
2390 | | - | |
2391 | | - | |
| 2390 | + | |
| 2391 | + | |
2392 | 2392 | | |
2393 | 2393 | | |
2394 | 2394 | | |
| |||
0 commit comments