diff options
| author | Ben Kimock <kimockb@gmail.com> | 2022-01-08 23:55:09 -0500 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2022-03-29 11:05:24 -0400 |
| commit | 6e6d0cbf838fef856abd5b5c63d1f156c4ebfe72 (patch) | |
| tree | da08d09e5c771f37b3072c25a8df157a2e956729 /compiler/rustc_data_structures | |
| parent | ba14a836c7038da21f5e102aacc7e6d5964f79a6 (diff) | |
| download | rust-6e6d0cbf838fef856abd5b5c63d1f156c4ebfe72.tar.gz rust-6e6d0cbf838fef856abd5b5c63d1f156c4ebfe72.zip | |
Add debug assertions to some unsafe functions
These debug assertions are all implemented only at runtime using `const_eval_select`, and in the error path they execute `intrinsics::abort` instead of being a normal debug assertion to minimize the impact of these assertions on code size, when enabled. Of all these changes, the bounds checks for unchecked indexing are expected to be most impactful (case in point, they found a problem in rustc).
Diffstat (limited to 'compiler/rustc_data_structures')
| -rw-r--r-- | compiler/rustc_data_structures/src/map_in_place.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/compiler/rustc_data_structures/src/map_in_place.rs b/compiler/rustc_data_structures/src/map_in_place.rs index 5dd9fc6e8bc..874de03d37a 100644 --- a/compiler/rustc_data_structures/src/map_in_place.rs +++ b/compiler/rustc_data_structures/src/map_in_place.rs @@ -30,13 +30,13 @@ impl<T> MapInPlace<T> for Vec<T> { while read_i < old_len { // move the read_i'th item out of the vector and map it // to an iterator - let e = ptr::read(self.get_unchecked(read_i)); + let e = ptr::read(self.as_ptr().add(read_i)); let iter = f(e).into_iter(); read_i += 1; for e in iter { if write_i < read_i { - ptr::write(self.get_unchecked_mut(write_i), e); + ptr::write(self.as_mut_ptr().add(write_i), e); write_i += 1; } else { // If this is reached we ran out of space @@ -76,13 +76,13 @@ impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> { while read_i < old_len { // move the read_i'th item out of the vector and map it // to an iterator - let e = ptr::read(self.get_unchecked(read_i)); + let e = ptr::read(self.as_ptr().add(read_i)); let iter = f(e).into_iter(); read_i += 1; for e in iter { if write_i < read_i { - ptr::write(self.get_unchecked_mut(write_i), e); + ptr::write(self.as_mut_ptr().add(write_i), e); write_i += 1; } else { // If this is reached we ran out of space |
