Closed
Description
Code
fn main() {
let mut x = Box::new(42u32);
let y = x.as_mut() as *mut u32;
let z = core::ptr::null();
unsafe {
core::ptr::copy(z, y, 1);
}
println!("Hello, world!");
}
Current output
thread 'main' panicked at library/core/src/panicking.rs:156:5:
unsafe precondition(s) violated: ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted (core dumped)
Desired output
thread 'main' panicked at library/core/src/panicking.rs:156:5:
unsafe precondition(s) violated: ptr::copy requires that both pointer arguments are aligned and non-null
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted (core dumped)
Rationale and extra context
rust/library/core/src/intrinsics.rs
Lines 3046 to 3047 in 921645c
The assert_unsafe_precondition
message for core::ptr::copy
is the one for core::ptr::copy_nonoverlapping
. The precondition itself seems correct, but the message is incorrect in that it not only names the wrong function but also the wrong requirements (i.e., the specified memory ranges do not overlap
which copy
explicitly allows).
Other cases
No response
Rust Version
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
Anything else?
No response