about summary refs log tree commit diff
path: root/library/alloc/src/string.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-09-16 08:25:02 +0200
committerGitHub <noreply@github.com>2020-09-16 08:25:02 +0200
commit9d0a265b6cfb0d6fbf3dbbf612cee1835b40bc35 (patch)
tree4a1d9dafc553ea2d3918dfe0e151be3197cd3f83 /library/alloc/src/string.rs
parent0bcc96dd3d54d459f3ae9a178bac3e7e944a9102 (diff)
parent7d67546a6ade5c1ade4b8e66266411f7aa4fae69 (diff)
downloadrust-9d0a265b6cfb0d6fbf3dbbf612cee1835b40bc35.tar.gz
rust-9d0a265b6cfb0d6fbf3dbbf612cee1835b40bc35.zip
Rollup merge of #76662 - RalfJung:lib-test-miri, r=Mark-Simulacrum
Fix liballoc test suite for Miri

Mostly, fix the regression introduced by https://github.com/rust-lang/rust/pull/75207 that caused slices (i.e., references) to be created to invalid memory or memory that has aliasing pointers that we want to keep valid. @dylni  this changes the type of `check_range` to only require the length, not the full reference to the slice, which indeed is all the information this function requires.

Also reduce the size of a test introduced in https://github.com/rust-lang/rust/pull/70793 to make it not take 3 minutes in Miri.

This makes https://github.com/RalfJung/miri-test-libstd work again.
Diffstat (limited to 'library/alloc/src/string.rs')
-rw-r--r--library/alloc/src/string.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index e1724bf3c9a..2b0ce5ede56 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -49,6 +49,7 @@ use core::iter::{FromIterator, FusedIterator};
 use core::ops::Bound::{Excluded, Included, Unbounded};
 use core::ops::{self, Add, AddAssign, Index, IndexMut, Range, RangeBounds};
 use core::ptr;
+use core::slice;
 use core::str::{lossy, pattern::Pattern};
 
 use crate::borrow::{Cow, ToOwned};
@@ -1506,7 +1507,7 @@ impl String {
         // of the vector version. The data is just plain bytes.
         // Because the range removal happens in Drop, if the Drain iterator is leaked,
         // the removal will not happen.
-        let Range { start, end } = self.as_bytes().check_range(range);
+        let Range { start, end } = slice::check_range(self.len(), range);
         assert!(self.is_char_boundary(start));
         assert!(self.is_char_boundary(end));