about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-13 01:49:26 +0200
committerGitHub <noreply@github.com>2019-06-13 01:49:26 +0200
commita1ff450a68e115e884f3ced8ba17fe5971202da4 (patch)
treeecc8eb6011832a3a03a135a0604f7ba77d33606b /src/libcore/tests
parentb35aeae5b443e9c3b2ae66eb40c6e31be36d2dcd (diff)
parent427f1a49f677395fbc4415f2917207fb7e4bc061 (diff)
downloadrust-a1ff450a68e115e884f3ced8ba17fe5971202da4.tar.gz
rust-a1ff450a68e115e884f3ced8ba17fe5971202da4.zip
Rollup merge of #61398 - kennytm:stabilize-copy-within, r=SimonSapin
Stabilize copy_within

Closes #54236.
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/lib.rs1
-rw-r--r--src/libcore/tests/slice.rs14
2 files changed, 14 insertions, 1 deletions
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs
index 928bdd7a760..bf072a9243b 100644
--- a/src/libcore/tests/lib.rs
+++ b/src/libcore/tests/lib.rs
@@ -28,7 +28,6 @@
 #![feature(inner_deref)]
 #![feature(slice_internals)]
 #![feature(slice_partition_dedup)]
-#![feature(copy_within)]
 #![feature(int_error_matching)]
 #![feature(const_fn)]
 #![warn(rust_2018_idioms)]
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs
index 9710f019f4e..eaa799fa96e 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -1512,6 +1512,13 @@ fn test_copy_within() {
     let mut bytes = *b"Hello, World!";
     bytes.copy_within(.., 0);
     assert_eq!(&bytes, b"Hello, World!");
+
+    // Ensure that copying at the end of slice won't cause UB.
+    let mut bytes = *b"Hello, World!";
+    bytes.copy_within(13..13, 5);
+    assert_eq!(&bytes, b"Hello, World!");
+    bytes.copy_within(5..5, 13);
+    assert_eq!(&bytes, b"Hello, World!");
 }
 
 #[test]
@@ -1536,6 +1543,13 @@ fn test_copy_within_panics_src_inverted() {
     // 2 is greater than 1, so this range is invalid.
     bytes.copy_within(2..1, 0);
 }
+#[test]
+#[should_panic(expected = "attempted to index slice up to maximum usize")]
+fn test_copy_within_panics_src_out_of_bounds() {
+    let mut bytes = *b"Hello, World!";
+    // an inclusive range ending at usize::max_value() would make src_end overflow
+    bytes.copy_within(usize::max_value()..=usize::max_value(), 0);
+}
 
 #[test]
 fn test_is_sorted() {