about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlbin Hedman <albin9604@gmail.com>2021-06-15 19:22:31 +0200
committerAlbin Hedman <albin9604@gmail.com>2021-06-27 12:05:22 +0200
commit56c78b2f5998315aafc9ee7f108160a7220b084f (patch)
treeccd89d2cbb7eadb8186b3301f8475efc2e62b747
parent3a894e38fb4e3f2fb129043bd6d0b88e25f5857d (diff)
downloadrust-56c78b2f5998315aafc9ee7f108160a7220b084f.tar.gz
rust-56c78b2f5998315aafc9ee7f108160a7220b084f.zip
Fix the test copy-intrinsic
-rw-r--r--src/test/ui/consts/copy-intrinsic.rs23
-rw-r--r--src/test/ui/consts/copy-intrinsic.stderr58
2 files changed, 31 insertions, 50 deletions
diff --git a/src/test/ui/consts/copy-intrinsic.rs b/src/test/ui/consts/copy-intrinsic.rs
index 9dc595f37fa..770c9c69226 100644
--- a/src/test/ui/consts/copy-intrinsic.rs
+++ b/src/test/ui/consts/copy-intrinsic.rs
@@ -1,19 +1,30 @@
+#![stable(feature = "dummy", since = "1.0.0")]
+
 // ignore-tidy-linelength
+#![feature(intrinsics, staged_api)]
 #![feature(const_mut_refs, const_intrinsic_copy, const_ptr_offset)]
-use std::{ptr, mem};
+use std::mem;
+
+extern "rust-intrinsic" {
+    #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
+    fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
+
+    #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
+    fn copy<T>(src: *const T, dst: *mut T, count: usize);
+}
 
 const COPY_ZERO: () = unsafe {
     // Since we are not copying anything, this should be allowed.
     let src = ();
     let mut dst = ();
-    ptr::copy_nonoverlapping(&src as *const _ as *const i32, &mut dst as *mut _ as *mut i32, 0);
+    copy_nonoverlapping(&src as *const _ as *const i32, &mut dst as *mut _ as *mut i32, 0);
 };
 
 const COPY_OOB_1: () = unsafe {
     let mut x = 0i32;
     let dangle = (&mut x as *mut i32).wrapping_add(10);
     // Even if the first ptr is an int ptr and this is a ZST copy, we should detect dangling 2nd ptrs.
-    ptr::copy_nonoverlapping(0x100 as *const i32, dangle, 0); //~ ERROR any use of this value will cause an error
+    copy_nonoverlapping(0x100 as *const i32, dangle, 0); //~ ERROR any use of this value will cause an error
     //~| memory access failed: pointer must be in-bounds
     //~| previously accepted
 };
@@ -21,7 +32,7 @@ const COPY_OOB_2: () = unsafe {
     let x = 0i32;
     let dangle = (&x as *const i32).wrapping_add(10);
     // Even if the second ptr is an int ptr and this is a ZST copy, we should detect dangling 1st ptrs.
-    ptr::copy_nonoverlapping(dangle, 0x100 as *mut i32, 0); //~ ERROR any use of this value will cause an error
+    copy_nonoverlapping(dangle, 0x100 as *mut i32, 0); //~ ERROR any use of this value will cause an error
     //~| memory access failed: pointer must be in-bounds
     //~| previously accepted
 };
@@ -29,14 +40,14 @@ const COPY_OOB_2: () = unsafe {
 const COPY_SIZE_OVERFLOW: () = unsafe {
     let x = 0;
     let mut y = 0;
-    ptr::copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
+    copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
     //~| overflow computing total size of `copy`
     //~| previously accepted
 };
 const COPY_NONOVERLAPPING_SIZE_OVERFLOW: () = unsafe {
     let x = 0;
     let mut y = 0;
-    ptr::copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
+    copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
     //~| overflow computing total size of `copy_nonoverlapping`
     //~| previously accepted
 };
diff --git a/src/test/ui/consts/copy-intrinsic.stderr b/src/test/ui/consts/copy-intrinsic.stderr
index fb6e5aaaa08..4bb8f500063 100644
--- a/src/test/ui/consts/copy-intrinsic.stderr
+++ b/src/test/ui/consts/copy-intrinsic.stderr
@@ -1,20 +1,13 @@
 error: any use of this value will cause an error
-  --> $SRC_DIR/core/src/intrinsics.rs:LL:COL
-   |
-LL |       unsafe { copy_nonoverlapping(src, dst, count) }
-   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |                |
-   |                memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc4 which has size 4
-   |                inside `copy_nonoverlapping::<i32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
-   |                inside `COPY_OOB_1` at $DIR/copy-intrinsic.rs:16:5
-   | 
-  ::: $DIR/copy-intrinsic.rs:12:1
+  --> $DIR/copy-intrinsic.rs:27:5
    |
 LL | / const COPY_OOB_1: () = unsafe {
 LL | |     let mut x = 0i32;
 LL | |     let dangle = (&mut x as *mut i32).wrapping_add(10);
 LL | |     // Even if the first ptr is an int ptr and this is a ZST copy, we should detect dangling 2nd ptrs.
-...  |
+LL | |     copy_nonoverlapping(0x100 as *const i32, dangle, 0);
+   | |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc4 which has size 4
+LL | |
 LL | |
 LL | | };
    | |__-
@@ -24,22 +17,15 @@ LL | | };
    = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
 
 error: any use of this value will cause an error
-  --> $SRC_DIR/core/src/intrinsics.rs:LL:COL
-   |
-LL |       unsafe { copy_nonoverlapping(src, dst, count) }
-   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |                |
-   |                memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc6 which has size 4
-   |                inside `copy_nonoverlapping::<i32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
-   |                inside `COPY_OOB_2` at $DIR/copy-intrinsic.rs:24:5
-   | 
-  ::: $DIR/copy-intrinsic.rs:20:1
+  --> $DIR/copy-intrinsic.rs:35:5
    |
 LL | / const COPY_OOB_2: () = unsafe {
 LL | |     let x = 0i32;
 LL | |     let dangle = (&x as *const i32).wrapping_add(10);
 LL | |     // Even if the second ptr is an int ptr and this is a ZST copy, we should detect dangling 1st ptrs.
-...  |
+LL | |     copy_nonoverlapping(dangle, 0x100 as *mut i32, 0);
+   | |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc6 which has size 4
+LL | |
 LL | |
 LL | | };
    | |__-
@@ -48,21 +34,13 @@ LL | | };
    = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
 
 error: any use of this value will cause an error
-  --> $SRC_DIR/core/src/intrinsics.rs:LL:COL
-   |
-LL |       unsafe { copy(src, dst, count) }
-   |                ^^^^^^^^^^^^^^^^^^^^^
-   |                |
-   |                overflow computing total size of `copy`
-   |                inside `std::intrinsics::copy::<i32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
-   |                inside `COPY_SIZE_OVERFLOW` at $DIR/copy-intrinsic.rs:32:5
-   | 
-  ::: $DIR/copy-intrinsic.rs:29:1
+  --> $DIR/copy-intrinsic.rs:43:5
    |
 LL | / const COPY_SIZE_OVERFLOW: () = unsafe {
 LL | |     let x = 0;
 LL | |     let mut y = 0;
-LL | |     ptr::copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
+LL | |     copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
+   | |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy`
 LL | |
 LL | |
 LL | | };
@@ -72,21 +50,13 @@ LL | | };
    = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
 
 error: any use of this value will cause an error
-  --> $SRC_DIR/core/src/intrinsics.rs:LL:COL
-   |
-LL |       unsafe { copy_nonoverlapping(src, dst, count) }
-   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |                |
-   |                overflow computing total size of `copy_nonoverlapping`
-   |                inside `copy_nonoverlapping::<i32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
-   |                inside `COPY_NONOVERLAPPING_SIZE_OVERFLOW` at $DIR/copy-intrinsic.rs:39:5
-   | 
-  ::: $DIR/copy-intrinsic.rs:36:1
+  --> $DIR/copy-intrinsic.rs:50:5
    |
 LL | / const COPY_NONOVERLAPPING_SIZE_OVERFLOW: () = unsafe {
 LL | |     let x = 0;
 LL | |     let mut y = 0;
-LL | |     ptr::copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
+LL | |     copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
+   | |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy_nonoverlapping`
 LL | |
 LL | |
 LL | | };