You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){letmut x = Box::new(42u32);let y = x.as_mut()as*mutu32;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)
"ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null \
and the specified memory ranges do not overlap",
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).
Noratrieb
added
C-bug
Category: This is a bug.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
and removed
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jun 13, 2024
…copy, r=Nilstrieb
Fix wrong `assert_unsafe_precondition` message for `core::ptr::copy`
A small fix in the `assert_unsafe_precondition` message for `core::ptr::copy` as described by rust-lang#126400 .
fixesrust-lang#126400
…copy, r=Nilstrieb
Fix wrong `assert_unsafe_precondition` message for `core::ptr::copy`
A small fix in the `assert_unsafe_precondition` message for `core::ptr::copy` as described by rust-lang#126400 .
fixesrust-lang#126400
Rollup merge of rust-lang#126402 - firefighterduck:fix-unsafe-precon-copy, r=Nilstrieb
Fix wrong `assert_unsafe_precondition` message for `core::ptr::copy`
A small fix in the `assert_unsafe_precondition` message for `core::ptr::copy` as described by rust-lang#126400 .
fixesrust-lang#126400
flip1995
pushed a commit
to flip1995/rust-clippy
that referenced
this issue
Jun 28, 2024
…ilstrieb
Fix wrong `assert_unsafe_precondition` message for `core::ptr::copy`
A small fix in the `assert_unsafe_precondition` message for `core::ptr::copy` as described by rust-lang/rust#126400 .
fixes #126400
Code
Current output
Desired output
Rationale and extra context
rust/library/core/src/intrinsics.rs
Lines 3046 to 3047 in 921645c
The
assert_unsafe_precondition
message forcore::ptr::copy
is the one forcore::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
whichcopy
explicitly allows).Other cases
No response
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: