Skip to content

Commit daad14f

Browse files
committed
Remove the DynMetadata special case in layout
1 parent 3b01da3 commit daad14f

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

compiler/rustc_middle/src/ty/layout.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -853,23 +853,10 @@ where
853853
// fall back to structurally deducing metadata.
854854
&& !pointee.references_error()
855855
{
856-
let metadata = tcx.normalize_erasing_regions(
856+
tcx.normalize_erasing_regions(
857857
cx.param_env(),
858858
Ty::new_projection(tcx, metadata_def_id, [pointee]),
859-
);
860-
861-
// Map `Metadata = DynMetadata<dyn Trait>` back to a vtable, since it
862-
// offers better information than `std::ptr::metadata::VTable`,
863-
// and we rely on this layout information to trigger a panic in
864-
// `std::mem::uninitialized::<&dyn Trait>()`, for example.
865-
if let ty::Adt(def, args) = metadata.kind()
866-
&& Some(def.did()) == tcx.lang_items().dyn_metadata()
867-
&& args.type_at(0).is_trait()
868-
{
869-
mk_dyn_vtable()
870-
} else {
871-
metadata
872-
}
859+
)
873860
} else {
874861
match tcx.struct_tail_erasing_lifetimes(pointee, cx.param_env()).kind() {
875862
ty::Slice(_) | ty::Str => tcx.types.usize,

library/core/src/ptr/metadata.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,18 @@ impl<T: ?Sized> Clone for PtrComponents<T> {
177177
/// duplicated in multiple codegen units), and pointers to vtables of *different* types/traits can
178178
/// compare equal (since identical vtables can be deduplicated within a codegen unit).
179179
#[lang = "dyn_metadata"]
180+
// codegen assumes it can treat this as a single pointer
181+
#[repr(transparent)]
180182
pub struct DynMetadata<Dyn: ?Sized> {
181183
vtable_ptr: &'static VTable,
182184
phantom: crate::marker::PhantomData<Dyn>,
183185
}
184186

185-
extern "C" {
186-
/// Opaque type for accessing vtables.
187-
///
188-
/// Private implementation detail of `DynMetadata::size_of` etc.
189-
/// There is conceptually not actually any Abstract Machine memory behind this pointer.
190-
type VTable;
187+
/// This is not really what's behind a vtable, but the codegen tests want the
188+
/// pointers to get `dereferencable` metadata, for example, and there's currently
189+
/// no way to get that with `extern type`, which would otherwise be nicer.
190+
struct VTable {
191+
_stub: usize,
191192
}
192193

193194
impl<Dyn: ?Sized> DynMetadata<Dyn> {

0 commit comments

Comments
 (0)