DispatchFromDyn
rules allowing non-PhantomData
ZSTs in additional fields is unsound
#135220
Labels
C-bug
Category: This is a bug.
F-arbitrary_self_types
`#![feature(arbitrary_self_types)]`
F-dispatch_from_dyn
`#![feature(dispatch_from_dyn)]`
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
requires-nightly
This issue requires a nightly compiler in some way.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
DispatchFromDyn
implementations are only allowed when all fields besides the main “pointer” contain ZSTs. Beyond this, those field’s types aren’t really restricted. Since actually dispatching fromdyn
then involves effectively transmuting the whole struct acting as receiving pointer, this can transmute between ZSTs that encode additional properties at the type level.This isn't sound, as it breaks e.g. assumptions in the API of
qcell::TCell
, where the encoded assumption of the ZSTTCellOwner<T: 'static>
is that – for each typeT: 'static
– only one value of typeTCellOwner<T>
can ever be created.@rustbot label requires-nightly, I-unsound, F-dispatch_from_dyn, F-arbitrary_self_types, T-compiler
The rules should probably be changed to be like
CoerceUnsized
, requiring all fields besides the main “pointer” one to not only be zero-sized, but actually the typePhantomData
.Split from #135215 to track this issue independent of the question of its relevance to the stabilization of
derive(CoercePointee)
.The text was updated successfully, but these errors were encountered: