Skip to content

Remove static mut refs from drop tests#159143

Draft
NotPppp1116 wants to merge 9 commits into
rust-lang:mainfrom
NotPppp1116:agent-remove-static-mut-refs-test-counters
Draft

Remove static mut refs from drop tests#159143
NotPppp1116 wants to merge 9 commits into
rust-lang:mainfrom
NotPppp1116:agent-remove-static-mut-refs-test-counters

Conversation

@NotPppp1116

Copy link
Copy Markdown

Replace several static mut counters in drop and union UI tests with atomic counters.

These tests only need simple observable drop counts/order within a single test run. Using AtomicUsize/AtomicU8 with relaxed ordering preserves that behavior while removing stale #![allow(static_mut_refs)] allowances and the associated unsafe counter accesses.

Validation:

./x test tests/ui/drop/drop-count-assertion-16151.rs tests/ui/drop/same-alloca-reassigned-match-binding-16151.rs tests/ui/drop/destructor-run-for-expression-4734.rs tests/ui/drop/destructor-run-for-let-ignore-6892.rs tests/ui/drop/conditional-drop-10734.rs tests/ui/drop/repeat-drop.rs tests/ui/union/union-drop.rs tests/ui/union/union-drop-assign.rs

Result: 8 passed, 0 failed.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 11, 2026
@rust-log-analyzer

This comment has been minimized.

@asquared31415

asquared31415 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Not all targets support AtomicUsize::fetch_add, and I'm not sure if that is a concern for testing. I believe some (especially obscure T3) targets cross-compile the tests to their target, and the use of AtomicUsize::fetch_add could cause them to no longer be able to test. If the compiler team wants these tests to continue working for all targets, they may need to be disabled on non-atomic targets, or another approach should be used.

Edit: oh i just saw the review in #159144, the same concerns apply here.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] tests/ui/drop/conditional-drop-10734.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/drop/conditional-drop-10734.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/drop/conditional-drop-10734/a" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0530]: let bindings cannot shadow statics
##[error]  --> /checkout/tests/ui/drop/conditional-drop-10734.rs:10:13
   |

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler 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