Skip to content

Don't rely on Global handing out dangling pointers - #164034

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
maxdexh:global-alloc-dangling
Oct 10, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
maxdexh:global-alloc-dangling

Conversation

@maxdexh

@maxdexh maxdexh commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

View all comments

This code is incorrect and will leak memory once the global allocator supports zero-sized allocations, since Box doesn't deallocate zero-sized layouts

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 9, 2026
@maxdexh

maxdexh commented Oct 9, 2026 •

Copy link
Copy Markdown
Member Author

Probably going to regress debug mode/compile times. If it's too unreasonable, we can add private helper methods to Global to skip the second zero check.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 9, 2026
Don't rely on `Global` handing out dangling pointers
@maxdexh

This comment was marked as resolved.

@rust-log-analyzer

This comment was marked as resolved.

@rust-bors

This comment was marked as resolved.

@maxdexh
maxdexh force-pushed the global-alloc-dangling branch from 22c4772 to eece26e Compare October 9, 2026 13:20
@maxdexh

maxdexh commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment was marked as resolved.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 9, 2026
Don't rely on `Global` handing out dangling pointers
@rust-bors

rust-bors Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 086d3bd (086d3bdf917ca9f68280debc31ee2cf4d5ab366d)
Base parent: 76c9095 (76c90957b7e422c4b9c45192b0197214d7de5a54)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (086d3bd): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-0.3%, -0.3%] 1

Max RSS (memory usage)

Results (primary 1.9%, secondary 3.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.8% [3.1%, 4.5%] 2
Regressions ❌
(secondary)
3.3% [2.1%, 4.6%] 2
Improvements ✅
(primary)
-1.8% [-1.8%, -1.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.9% [-1.8%, 4.5%] 3

Cycles

Results (primary -0.4%, secondary 2.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
2.8% [2.8%, 2.8%] 1
Improvements ✅
(primary)
-3.0% [-3.0%, -3.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-3.0%, 2.2%] 2

Binary size

Results (primary -0.0%, secondary 0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.4%] 23
Regressions ❌
(secondary)
0.3% [0.0%, 0.6%] 16
Improvements ✅
(primary)
-0.2% [-0.6%, -0.0%] 15
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.0%] 2
All ❌✅ (primary) -0.0% [-0.6%, 0.4%] 38

Bootstrap: 490.84s -> 494.804s (0.81%)
Artifact size: 406.48 MiB -> 406.60 MiB (0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2026
@maxdexh

maxdexh commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Well that's nice

r? clarfonthey

@maxdexh
maxdexh marked this pull request as ready for review October 9, 2026 18:11
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 9, 2026
@rustbot

rustbot commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, aapoalas

@maxdexh

maxdexh commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Thank you rustbot for adding two reviewers

@maxdexh

maxdexh commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

I guess this didn't regress because we never mir inline this function, and llvm is smarter than mir-opt

@clarfonthey

Copy link
Copy Markdown
Contributor

So, just to get a read on this, we wouldn't need to backport this since GlobalAlloc always doesn't support ZSTs right now, right? Also, would Vec need a similar change?

@maxdexh

maxdexh commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

This is the only place in std where we did this, and yes, it is correct atm, so no backport needed.

@clarfonthey

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit eece26e has been approved by clarfonthey

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 10, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 10, 2026
@rust-bors

rust-bors Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: clarfonthey
Duration: 3h 3m 53s
Pushing 34f4a80 to main...

@rust-bors
rust-bors Bot merged commit 34f4a80 into rust-lang:main Oct 10, 2026
16 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing a5c142a (parent) -> 34f4a80 (this PR)

Test differences

Show 244 test diffs

244 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 34f4a807e2d84184fff4e42d4539092569b6fcd6 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. test-x86_64-msvc-ext2: 1h 2m -> 1h 51m (+79.7%)
  2. test-x86_64-gnu-debug: 1h 12m -> 2h 1m (+67.0%)
  3. dist-x86_64-mingw: 1h 39m -> 2h 45m (+65.4%)
  4. test-i686-gnu-nopt-1: 1h 22m -> 2h 14m (+64.3%)
  5. test-x86_64-gnu: 1h 32m -> 2h 30m (+62.7%)
  6. dist-x86_64-musl: 1h 26m -> 2h 18m (+60.3%)
  7. dist-powerpc64-linux-musl: 1h 7m -> 1h 38m (+46.9%)
  8. dist-armhf-linux: 1h 4m -> 1h 31m (+42.6%)
  9. test-i686-gnu-nopt-2: 2h 21m -> 1h 21m (-42.6%)
  10. test-x86_64-msvc-2: 2h 37m -> 1h 35m (-39.1%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (34f4a80): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 1
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) -0.2% [-0.2%, -0.2%] 1

Max RSS (memory usage)

Results (primary 0.8%, secondary -2.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.1% [0.9%, 5.5%] 5
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.1% [-4.1%, -1.2%] 4
Improvements ✅
(secondary)
-2.4% [-3.3%, -1.1%] 9
All ❌✅ (primary) 0.8% [-4.1%, 5.5%] 9

Cycles

This perf run didn't have relevant results for this metric.

Binary size

Results (primary -0.0%, secondary 0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.4%] 23
Regressions ❌
(secondary)
0.3% [0.0%, 0.6%] 17
Improvements ✅
(primary)
-0.2% [-0.6%, -0.0%] 15
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.0%] 2
All ❌✅ (primary) -0.0% [-0.6%, 0.4%] 38

Bootstrap: 486.952s -> 489.09s (0.44%)
Artifact size: 406.48 MiB -> 406.52 MiB (0.01%)

@maxdexh
maxdexh deleted the global-alloc-dangling branch October 10, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. 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.

6 participants