Skip to content

Conversation

@m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Nov 5, 2025

Removes the use of fmt::Arguments unstable implementation details fom the assert_unsafe_precondition expansion.

The fewer places that rely on the exact implementation details of fmt::Arguments, the better.

Also, see #129658 (comment)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 5, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@saethlin
Copy link
Member

saethlin commented Nov 5, 2025

If you want to do this, you need to add #[track_caller] to panic_nounwind. Otherwise you completely neutralize the helpful caller location added in #129658. You should also probably update the documentationon panic_nounwind which says to do what I did in that PR:

/// If you want `#[track_caller]` for nicer errors, call `panic_nounwind_fmt` directly.

@m-ou-se m-ou-se force-pushed the ub-checks-panic-nounwind-no-fmt branch from 640d372 to 979d559 Compare November 5, 2025 15:37
@rustbot
Copy link
Collaborator

rustbot commented Nov 5, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/fail/tree_borrows/reserved/cell-protected-write.rs ... ok
tests/fail/tree_borrows/reserved/int-protected-write.rs ... ok

FAILED TEST: tests/fail/ptr_swap_nonoverlapping.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-9cZ6C8" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail" "tests/fail/ptr_swap_nonoverlapping.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/ptr_swap_nonoverlapping.stderr` to the actual output
--- tests/fail/ptr_swap_nonoverlapping.stderr
+++ <stderr output>
 
-thread 'main' ($TID) panicked at tests/fail/ptr_swap_nonoverlapping.rs:LL:CC:
+thread 'main' ($TID) panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
 unsafe precondition(s) violated: ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap
 
... 13 lines skipped ...
    = note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::panic_handler::{closure#0}}, !>` at RUSTLIB/std/src/sys/backtrace.rs:LL:CC
    = note: inside `std::panicking::panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
+   = note: inside `core::panicking::panic_nounwind` at RUSTLIB/core/src/panicking.rs:LL:CC
 note: inside `main`
   --> tests/fail/ptr_swap_nonoverlapping.rs:LL:CC
... 6 lines skipped ...
 error: aborting due to 1 previous error
 

Full unnormalized output:

thread 'main' (1000) panicked at /checkout/library/core/src/panicking.rs:230:5:
unsafe precondition(s) violated: ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap

This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
thread caused non-unwinding panic. aborting.
error: abnormal termination: the program aborted execution
##[error]  --> /checkout/library/std/src/panicking.rs:856:9
   |
LL |         crate::process::abort();
   |         ^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
   |
   = note: BACKTRACE:
   = note: inside `std::panicking::panic_with_hook` at /checkout/library/std/src/panicking.rs:856:9: 856:32
   = note: inside closure at /checkout/library/std/src/panicking.rs:700:13: 705:14
   = note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::panic_handler::{closure#0}}, !>` at /checkout/library/std/src/sys/backtrace.rs:174:18: 174:21
   = note: inside `std::panicking::panic_handler` at /checkout/library/std/src/panicking.rs:698:5: 714:7
   = note: inside `core::panicking::panic_nounwind` at /checkout/library/core/src/panicking.rs:230:5: 230:91
note: inside `main`
  --> tests/fail/ptr_swap_nonoverlapping.rs:11:9
   |
---

full stderr:

thread 'main' (1000) panicked at /checkout/library/core/src/panicking.rs:230:5:
unsafe precondition(s) violated: ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap

This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
thread caused non-unwinding panic. aborting.
error: abnormal termination: the program aborted execution
##[error]  --> /checkout/library/std/src/panicking.rs:856:9
   |
LL |         crate::process::abort();
   |         ^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
   |
   = note: BACKTRACE:
   = note: inside `std::panicking::panic_with_hook` at /checkout/library/std/src/panicking.rs:856:9: 856:32
   = note: inside closure at /checkout/library/std/src/panicking.rs:700:13: 705:14
   = note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::panic_handler::{closure#0}}, !>` at /checkout/library/std/src/sys/backtrace.rs:174:18: 174:21
   = note: inside `std::panicking::panic_handler` at /checkout/library/std/src/panicking.rs:698:5: 714:7
   = note: inside `core::panicking::panic_nounwind` at /checkout/library/core/src/panicking.rs:230:5: 230:91
note: inside `main`
  --> tests/fail/ptr_swap_nonoverlapping.rs:11:9
   |
---
Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.30.2/src/lib.rs:365

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   1: <color_eyre[721416e7479139d5]::config::EyreHook>::into_eyre_hook::{closure#0}<unknown>
      at <unknown source file>:<unknown line>
   2: eyre[71cec50363be3d04]::private::format_err<unknown>
      at <unknown source file>:<unknown line>
   3: ui_test[db9dc9bd31952c99]::run_tests_generic::<ui_test[db9dc9bd31952c99]::default_file_filter, ui[245f8b8a112c2145]::run_tests::{closure#1}, alloc[7b765a68cb2974d6]::boxed::Box<dyn ui_test[db9dc9bd31952c99]::status_emitter::StatusEmitter>><unknown>
      at <unknown source file>:<unknown line>
   4: ui[245f8b8a112c2145]::ui<unknown>
      at <unknown source file>:<unknown line>
   5: ui[245f8b8a112c2145]::main<unknown>
      at <unknown source file>:<unknown line>
   6: std[ec331c49c61a77c5]::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core[91af1086ea0fee1b]::result::Result<(), eyre[71cec50363be3d04]::Report>, core[91af1086ea0fee1b]::result::Result<(), eyre[71cec50363be3d04]::Report>><unknown>
      at <unknown source file>:<unknown line>
   7: std[ec331c49c61a77c5]::rt::lang_start::<core[91af1086ea0fee1b]::result::Result<(), eyre[71cec50363be3d04]::Report>>::{closure#0}<unknown>
      at <unknown source file>:<unknown line>
   8: std[ec331c49c61a77c5]::rt::lang_start_internal<unknown>
      at <unknown source file>:<unknown line>
   9: main<unknown>
      at <unknown source file>:<unknown line>
  10: __libc_start_main<unknown>
      at <unknown source file>:<unknown line>
  11: _start<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/ui-60d430e8ea50df4d` (exit status: 1)
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo test --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color always --release --manifest-path /checkout/src/tools/miri/Cargo.toml -- [workdir=/checkout]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:191:21
Executed at: src/bootstrap/src/core/build_steps/test.rs:676:19

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test --stage 2 src/tools/miri src/tools/miri/cargo-miri`
Build completed unsuccessfully in 0:40:07
  local time: Wed Nov  5 16:28:38 UTC 2025
  network time: Wed, 05 Nov 2025 16:28:38 GMT
##[error]Process completed with exit code 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants