-
-
Notifications
You must be signed in to change notification settings - Fork 15k
DispatchFromDyn rules allowing non-PhantomData ZSTs in additional fields is unsound #135220
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-arbitrary_self_types`#![feature(arbitrary_self_types)]``#![feature(arbitrary_self_types)]`F-dispatch_from_dyn`#![feature(dispatch_from_dyn)]``#![feature(dispatch_from_dyn)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-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.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-arbitrary_self_types`#![feature(arbitrary_self_types)]``#![feature(arbitrary_self_types)]`F-dispatch_from_dyn`#![feature(dispatch_from_dyn)]``#![feature(dispatch_from_dyn)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-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.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Type
Fields
Give feedbackNo fields configured for issues without a type.
DispatchFromDynimplementations 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 fromdynthen 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).