ptr::metadata: update comment on vtable_ptr work-around · patricklam/verify-rust-std@89cd225
@@ -167,10 +167,13 @@ extern "C" {
167167}
168168169169impl<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]
175178fn vtable_ptr(self) -> *const VTable {
176179// SAFETY: this layout assumption is hard-coded into the compiler.