Skip to content

Commit f9c0d33

Browse files
committed
ptr::metadata: update comment on vtable_ptr work-around
1 parent 21dc49c commit f9c0d33

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

library/core/src/ptr/metadata.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,13 @@ extern "C" {
167167
}
168168

169169
impl<Dyn: ?Sized> DynMetadata<Dyn> {
170-
/// One of the things that rustc_middle does with this being a lang item is
171-
/// give it `FieldsShape::Primitive`, which means that as far as codegen can
172-
/// tell, it *is* a reference, and thus doesn't have any fields.
173-
/// That means we can't use field access, and have to transmute it instead.
170+
/// When `DynMetadata` appears as the metadata field of a wide pointer, the rustc_middle layout
171+
/// computation does magic and the resulting layout is *not* a `FieldsShape::Aggregate`, instead
172+
/// it is a `FieldsShape::Primitive`. This means that the same type can have different layout
173+
/// depending on whether it appears as the metadata field of a wide pointer or as a stand-alone
174+
/// type, which understandably confuses codegen and leads to ICEs when trying to project to a
175+
/// field of `DynMetadata`. To work around that issue, we use `transmute` instead of using a
176+
/// field projection.
174177
#[inline]
175178
fn vtable_ptr(self) -> *const VTable {
176179
// SAFETY: this layout assumption is hard-coded into the compiler.

0 commit comments

Comments
 (0)