From 6e6d0cbf838fef856abd5b5c63d1f156c4ebfe72 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 8 Jan 2022 23:55:09 -0500 Subject: 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). --- compiler/rustc_data_structures/src/map_in_place.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_data_structures') 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 MapInPlace for Vec { 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> MapInPlace for SmallVec { 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 -- cgit 1.4.1-3-g733a5