Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core::ptr::copy unsafe precondition message is for core::ptr::copy_nonoverlapping instead #126400

Closed
firefighterduck opened this issue Jun 13, 2024 · 0 comments · Fixed by #126402
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@firefighterduck
Copy link
Contributor

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

"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).

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

@firefighterduck firefighterduck added 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
@Noratrieb 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
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue 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 .

fixes rust-lang#126400
workingjubilee added a commit to workingjubilee/rustc that referenced this issue 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 .

fixes rust-lang#126400
@bors bors closed this as completed in 3494ea1 Jun 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 14, 2024
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 .

fixes rust-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants