Addresses miri's complaints about vtable shenanigans in MetaTable implementation.
Before pointer casts and reads/deferences were used to extract/attach a vtable pointer as a usize (which includes operations that miri reports as UB). Now a function pointer is stored for each concrete type, this points to a function that knows the types involved and can thus leverage safe code to upcast a pointer from the concrete type to a trait object.
CastFrom trait now uses a single method that operates on pointers rather than two separate methods for &T and &mut T (this is so that we don't have to store a separate function pointer for each case). Safety requirements for implementing CastFrom having been modified (but can be trivially met by just returning the provided pointer (letting it be automatically coerced to a pointer to the trait object)).
MetaTable::register no longer requires an instance of the type being registered.
MetaTable::get_mut no longer converts a shared reference to an exclusive one (this was most likely UB).
MetaIter/MetaIterMut no longer cast aside the Ref/RefMut guard on each element (which would allow safe code to create aliasing references to items being yielded from these iterators). Instead, Ref::map and RefMut::map are used.
Converted meta iterators to use a loop rather than recursion for advancing past missing values from try_fetch_internal (not sure if this avoids impacting performance though...).
Misc changes:
Added crate-level deny for unsafe_op_in_unsafe_fn and added unsafe blocks where needed. This makes it easier to identify where unsafe operations are occuring and to document them.
Bump MSRV to 1.65.0, since we are already bumping it in specs to use GATs and it gives some convenient functions for working with pointers.
Remove unnecessary extern crates in benches/bench.rs (not needed in newer rust editions).
Update: This now adds a nightly feature which uses the unstable ptr_metadata feature for a more efficient implementation of the MetaTable.
Addresses miri's complaints about vtable shenanigans in MetaTable implementation.
usize
(which includes operations that miri reports as UB). Now a function pointer is stored for each concrete type, this points to a function that knows the types involved and can thus leverage safe code to upcast a pointer from the concrete type to a trait object.CastFrom
trait now uses a single method that operates on pointers rather than two separate methods for&T
and&mut T
(this is so that we don't have to store a separate function pointer for each case). Safety requirements for implementingCastFrom
having been modified (but can be trivially met by just returning the provided pointer (letting it be automatically coerced to a pointer to the trait object)).MetaTable::register
no longer requires an instance of the type being registered.MetaTable::get_mut
no longer converts a shared reference to an exclusive one (this was most likely UB).MetaIter
/MetaIterMut
no longer cast aside theRef
/RefMut
guard on each element (which would allow safe code to create aliasing references to items being yielded from these iterators). Instead,Ref::map
andRefMut::map
are used.Misc changes:
unsafe_op_in_unsafe_fn
and added unsafe blocks where needed. This makes it easier to identify where unsafe operations are occuring and to document them.extern crate
s in benches/bench.rs (not needed in newer rust editions).Update: This now adds a
nightly
feature which uses the unstableptr_metadata
feature for a more efficient implementation of theMetaTable
.