Use pointer casts instead of tramsutes to raw::TraitObject

Casting `*const T` to `*const U` with `U: Sized` is allowed even if `T: ?Sized`.
This safely extracts the data pointer out of a trait object,
without relying on the memory representation of trait objects.
This commit is contained in:
Simon Sapin 2017-10-13 21:55:11 +02:00
parent 78aaa85aec
commit e7c53d4ca2
3 changed files with 10 additions and 52 deletions

View file

@ -90,12 +90,3 @@ pub use self::data::LayoutData;
// We can't use servo_arc for everything in layout, because the Flow stuff uses
// weak references.
use servo_arc::Arc as ServoArc;
/// Stable copy of std::raw::TraitObject
/// test/unit/layout/lib.rs asserts that the memory layout matches.
#[repr(C)]
#[derive(Clone, Copy)]
pub struct TraitObject {
pub data: *mut (),
pub vtable: *mut (),
}