Fix a dangling reference in rustc_thread_pool#146799
Merged
bors merged 1 commit intorust-lang:masterfrom Sep 23, 2025
Merged
Conversation
Collaborator
hkBst
suggested changes
Sep 21, 2025
Comment on lines
+391
to
393
| // SAFETY: Once we call `set` on the internal `latch`, | ||
| // the target may proceed and invalidate `this`! | ||
| match unsafe { &(*this).kind } { |
Member
There was a problem hiding this comment.
A safety comment here should explain why it is safe to create a reference out of (*this).kind. That it does not seem to do that, may be the reason it is a NOTE.
Member
Author
There was a problem hiding this comment.
Well, we added the NOTE in rayon before there was much consensus on proper SAFETY comments. It's definitely a safety-relevant comment, even if it's not directly justifying this unsafe.
(Personally, I would have used a single unsafe block around all of this, but this was also added after the port from rayon. Originally, it's still using the unsafe fn context for inner unsafe too.)
lcnr
reviewed
Sep 22, 2025
57382b2 to
389a502
Compare
Member
Author
|
Thanks for the review -- I added another SAFETY comment as requested. @bors r=lcnr |
Collaborator
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Sep 23, 2025
Fix a dangling reference in `rustc_thread_pool` This diverged from `rayon` in rust-lang#142384, where a cleanup commit turned the matched `worker_index` into a reference, which is read _after_ the `set` that may kill it. I've moved that read beforehand, and I hope the new comments will emphasize the subtlety of this unsafe code. Hopefully fixes rust-lang#146677.
bors
added a commit
that referenced
this pull request
Sep 23, 2025
Rollup of 13 pull requests Successful merges: - #146632 (Fix uses of "adaptor") - #146731 (test: Use SVG for terminal url test) - #146775 (fixes for numerous clippy warnings) - #146784 ([win] Use find-msvc-tools instead of cc to find the linker and rc on Windows) - #146799 (Fix a dangling reference in `rustc_thread_pool`) - #146802 (mbe: Simplifications and refactoring) - #146806 (add private module override re-export test) - #146827 (Linker-plugin-based LTO: update list of good combinations (inc. beta + nightly)) - #146875 (tests/run-make/crate-loading: Rename source files for clarity) - #146896 (rustc-dev-guide subtree update) - #146898 (Update books) - #146899 (Fix a crash/mislex when more than one frontmatter closing possibility is considered) - #146907 (add regression test for issue 146537) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
that referenced
this pull request
Sep 23, 2025
Rollup of 10 pull requests Successful merges: - #146632 (Fix uses of "adaptor") - #146731 (test: Use SVG for terminal url test) - #146775 (fixes for numerous clippy warnings) - #146784 ([win] Use find-msvc-tools instead of cc to find the linker and rc on Windows) - #146799 (Fix a dangling reference in `rustc_thread_pool`) - #146802 (mbe: Simplifications and refactoring) - #146806 (add private module override re-export test) - #146827 (Linker-plugin-based LTO: update list of good combinations (inc. beta + nightly)) - #146875 (tests/run-make/crate-loading: Rename source files for clarity) - #146877 (prevent line number from being copied in chrome) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Sep 23, 2025
Rollup merge of #146799 - cuviper:dangling-count-latch, r=lcnr Fix a dangling reference in `rustc_thread_pool` This diverged from `rayon` in #142384, where a cleanup commit turned the matched `worker_index` into a reference, which is read _after_ the `set` that may kill it. I've moved that read beforehand, and I hope the new comments will emphasize the subtlety of this unsafe code. Hopefully fixes #146677.
Muscraft
pushed a commit
to Muscraft/rust
that referenced
this pull request
Sep 24, 2025
Fix a dangling reference in `rustc_thread_pool` This diverged from `rayon` in rust-lang#142384, where a cleanup commit turned the matched `worker_index` into a reference, which is read _after_ the `set` that may kill it. I've moved that read beforehand, and I hope the new comments will emphasize the subtlety of this unsafe code. Hopefully fixes rust-lang#146677.
Muscraft
pushed a commit
to Muscraft/rust
that referenced
this pull request
Sep 24, 2025
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#146632 (Fix uses of "adaptor") - rust-lang#146731 (test: Use SVG for terminal url test) - rust-lang#146775 (fixes for numerous clippy warnings) - rust-lang#146784 ([win] Use find-msvc-tools instead of cc to find the linker and rc on Windows) - rust-lang#146799 (Fix a dangling reference in `rustc_thread_pool`) - rust-lang#146802 (mbe: Simplifications and refactoring) - rust-lang#146806 (add private module override re-export test) - rust-lang#146827 (Linker-plugin-based LTO: update list of good combinations (inc. beta + nightly)) - rust-lang#146875 (tests/run-make/crate-loading: Rename source files for clarity) - rust-lang#146877 (prevent line number from being copied in chrome) r? `@ghost` `@rustbot` modify labels: rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This diverged from
rayonin #142384, where a cleanup commit turned the matchedworker_indexinto a reference, which is read after thesetthat may kill it. I've moved that read beforehand, and I hope the new comments will emphasize the subtlety of this unsafe code.Hopefully fixes #146677.