ptr::metadata: avoid references to extern types · model-checking/verify-rust-std@51e54a4 (original) (raw)

Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ use crate::hash::{Hash, Hasher};
5 5 use crate::intrinsics::aggregate_raw_ptr;
6 6 use crate::intrinsics::ptr_metadata;
7 7 use crate:📑:Freeze;
8 +use crate::ptr::NonNull;
8 9
9 10 /// Provides the pointer metadata type of any pointed-to type.
10 11 ///
@@ -153,7 +154,7 @@ pub const fn from_raw_parts_mut<T: ?Sized>(
153 154 /// compare equal (since identical vtables can be deduplicated within a codegen unit).
154 155 #[lang = "dyn_metadata"]
155 156 pub struct DynMetadata<Dyn: ?Sized> {
156 -_vtable_ptr: &'static VTable,
157 +_vtable_ptr: NonNull<VTable>,
157 158 _phantom: crate:📑:PhantomData<Dyn>,
158 159 }
159 160
@@ -174,7 +175,7 @@ impl<Dyn: ?Sized> DynMetadata {
174 175 fn vtable_ptr(self) -> *const VTable {
175 176 // SAFETY: this layout assumption is hard-coded into the compiler.
176 177 // If it's somehow not a size match, the transmute will error.
177 -unsafe { crate::mem::transmute::<Self, &'static VTable>(self) }
178 +unsafe { crate::mem::transmute::<Self, *const VTable>(self) }
178 179 }
179 180
180 181 /// Returns the size of the type associated with this vtable.