Fix remaining issues identified by Miri #226
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
.