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.CastFromtrait now uses a single method that operates on pointers rather than two separate methods for&Tand&mut T(this is so that we don't have to store a separate function pointer for each case). Safety requirements for implementingCastFromhaving 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::registerno longer requires an instance of the type being registered.MetaTable::get_mutno longer converts a shared reference to an exclusive one (this was most likely UB).MetaIter/MetaIterMutno longer cast aside theRef/RefMutguard on each element (which would allow safe code to create aliasing references to items being yielded from these iterators). Instead,Ref::mapandRefMut::mapare used.Misc changes:
unsafe_op_in_unsafe_fnand added unsafe blocks where needed. This makes it easier to identify where unsafe operations are occuring and to document them.extern crates in benches/bench.rs (not needed in newer rust editions).Update: This now adds a
nightlyfeature which uses the unstableptr_metadatafeature for a more efficient implementation of theMetaTable.