Closed
Description
The following functions have restrictions which (ideally) should be respected:
get_unchecked
get_unchecked_mut
slice_unchecked
slice_mut_unchecked
unreachable_unchecked
- raw pointer deref (Check alignment of raw pointers in debug mode #54915)
- etc. (please comment if you know additional examples)
It would be nice to check these restrictions with debug asserts. The main blockers:
- stdlib is distributed with disabled debug assertions, so either implementation will have to use the same hack as in wrapping checks, or we'll have to distribute two versions of stdlib with enabled and disabled debug assertions, and teach
cargo
to switch between them depending on a compilation profile. - Some code in the stdlib (and probably in some external crates) consciously breaks those restrictions (e.g.
src/liballoc/vec.rs
). Probably it should be rewritten in a more "correct" fashion.
See internals thread for additional discussion.