Auto merge of #86003 - pnkfelix:issue-84297-revert-81238, r=Mark-Simulacrum
Make copy/copy_nonoverlapping fn's again Make copy/copy_nonoverlapping fn's again, rather than intrinsics. This a short-term change to address issue #84297. It effectively reverts PRs #81167 #81238 (and part of #82967), #83091, and parts of #79684.
This commit is contained in:
commit
eab201df70
15 changed files with 225 additions and 414 deletions
|
|
@ -1,16 +0,0 @@
|
|||
// error-pattern: any use of this value will cause an error
|
||||
|
||||
#![feature(const_ptr_read)]
|
||||
#![feature(const_ptr_offset)]
|
||||
|
||||
fn main() {
|
||||
use std::ptr;
|
||||
|
||||
const DATA: [u32; 1] = [42];
|
||||
|
||||
const PAST_END_PTR: *const u32 = unsafe { DATA.as_ptr().add(1) };
|
||||
|
||||
const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
|
||||
const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
|
||||
const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
error: any use of this value will cause an error
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
|
|
||||
LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4
|
||||
| inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
| inside `_READ` at $DIR/out_of_bounds_read.rs:13:33
|
||||
|
|
||||
::: $DIR/out_of_bounds_read.rs:13:5
|
||||
|
|
||||
LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
|
||||
| ------------------------------------------------------
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= 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/ptr/mod.rs:LL:COL
|
||||
|
|
||||
LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4
|
||||
| inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
| inside `ptr::const_ptr::<impl *const u32>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
| inside `_CONST_READ` at $DIR/out_of_bounds_read.rs:14:39
|
||||
|
|
||||
::: $DIR/out_of_bounds_read.rs:14:5
|
||||
|
|
||||
LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
|
||||
| --------------------------------------------------------
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= 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/ptr/mod.rs:LL:COL
|
||||
|
|
||||
LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4
|
||||
| inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
| inside `ptr::mut_ptr::<impl *mut u32>::read` at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
|
||||
| inside `_MUT_READ` at $DIR/out_of_bounds_read.rs:15:37
|
||||
|
|
||||
::: $DIR/out_of_bounds_read.rs:15:5
|
||||
|
|
||||
LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
|
||||
| --------------------------------------------------------------------
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// ignore-tidy-linelength
|
||||
#![feature(const_mut_refs, const_intrinsic_copy, const_ptr_offset)]
|
||||
use std::{ptr, mem};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
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
|
||||
//~| memory access failed: pointer must be in-bounds
|
||||
//~| previously accepted
|
||||
};
|
||||
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
|
||||
//~| memory access failed: pointer must be in-bounds
|
||||
//~| previously accepted
|
||||
};
|
||||
|
||||
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
|
||||
//~| 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
|
||||
//~| overflow computing total size of `copy_nonoverlapping`
|
||||
//~| previously accepted
|
||||
};
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
error: any use of this value will cause an error
|
||||
--> $DIR/copy-intrinsic.rs:16: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 | | ptr::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 | | };
|
||||
| |__-
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= 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
|
||||
--> $DIR/copy-intrinsic.rs:24: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 | | ptr::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 | | };
|
||||
| |__-
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= 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
|
||||
--> $DIR/copy-intrinsic.rs:32: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));
|
||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy`
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | };
|
||||
| |__-
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= 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
|
||||
--> $DIR/copy-intrinsic.rs:39: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));
|
||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy_nonoverlapping`
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | };
|
||||
| |__-
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
9
src/test/ui/intrinsics/issue-84297-reifying-copy.rs
Normal file
9
src/test/ui/intrinsics/issue-84297-reifying-copy.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// check-pass
|
||||
|
||||
fn main() {
|
||||
let _unused = if true {
|
||||
core::ptr::copy::<i32>
|
||||
} else {
|
||||
core::ptr::copy_nonoverlapping::<i32>
|
||||
};
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// check-fail
|
||||
|
||||
#![feature(intrinsics)]
|
||||
#![feature(core_intrinsics, intrinsics)]
|
||||
|
||||
fn a() {
|
||||
let _: unsafe extern "rust-intrinsic" fn(isize) -> usize = std::mem::transmute;
|
||||
|
|
@ -14,8 +14,8 @@ fn b() {
|
|||
|
||||
fn c() {
|
||||
let _ = [
|
||||
std::intrinsics::copy_nonoverlapping::<i32>,
|
||||
std::intrinsics::copy::<i32>,
|
||||
std::intrinsics::likely,
|
||||
std::intrinsics::unlikely,
|
||||
//~^ ERROR cannot coerce
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ LL | let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize)
|
|||
error[E0308]: cannot coerce intrinsics to function pointers
|
||||
--> $DIR/reify-intrinsic.rs:18:9
|
||||
|
|
||||
LL | std::intrinsics::copy::<i32>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers
|
||||
LL | std::intrinsics::unlikely,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers
|
||||
|
|
||||
= note: expected type `unsafe extern "rust-intrinsic" fn(_, _, _) {copy_nonoverlapping::<i32>}`
|
||||
found fn item `unsafe extern "rust-intrinsic" fn(_, _, _) {std::intrinsics::copy::<i32>}`
|
||||
= note: expected type `extern "rust-intrinsic" fn(_) -> _ {likely}`
|
||||
found fn item `extern "rust-intrinsic" fn(_) -> _ {unlikely}`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ const fn g(x: &mut [u32; 8]) {
|
|||
//~| ERROR mutable references are not allowed
|
||||
//~| ERROR use of mutable static is unsafe
|
||||
//~| constant functions cannot refer to statics
|
||||
//~| ERROR calls in constant functions are limited to constant functions
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ LL | std::mem::swap(x, &mut STATIC_VAR_2)
|
|||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/thread-local-static.rs:9:5
|
||||
|
|
||||
LL | std::mem::swap(x, &mut STATIC_VAR_2)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
|
||||
--> $DIR/thread-local-static.rs:9:23
|
||||
|
|
||||
|
|
@ -38,7 +44,7 @@ LL | std::mem::swap(x, &mut STATIC_VAR_2)
|
|||
|
|
||||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0013, E0133, E0658.
|
||||
Some errors have detailed explanations: E0013, E0015, E0133, E0658.
|
||||
For more information about an error, try `rustc --explain E0013`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue