-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add fn into_raw_with_allocator
to Rc/Arc/Weak.
#125093
Merged
bors
merged 2 commits into
rust-lang:master
from
zachs18:rc-into-raw-with-allocator-only
May 20, 2024
Merged
Add fn into_raw_with_allocator
to Rc/Arc/Weak.
#125093
bors
merged 2 commits into
rust-lang:master
from
zachs18:rc-into-raw-with-allocator-only
May 20, 2024
Conversation
This file contains 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
rustbot has assigned @Mark-Simulacrum. Use |
rustbot
added
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
labels
May 13, 2024
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
rustbot
added
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
May 14, 2024
... since fn allocator doesn't exist yet.
rustbot
added
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
May 17, 2024
@bors r+ |
bors
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
May 19, 2024
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 20, 2024
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#125034 (Weekly `cargo update`) - rust-lang#125093 (Add `fn into_raw_with_allocator` to Rc/Arc/Weak.) - rust-lang#125282 (Never type unsafe lint improvements) - rust-lang#125301 (fix suggestion in E0373 for !Unpin coroutines) - rust-lang#125302 (defrost `RUST_MIN_STACK=ice rustc hello.rs`) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 20, 2024
Rollup merge of rust-lang#125093 - zachs18:rc-into-raw-with-allocator-only, r=Mark-Simulacrum Add `fn into_raw_with_allocator` to Rc/Arc/Weak. Split out from rust-lang#119761 Add `fn into_raw_with_allocator` for `Rc`/`rc::Weak`[^1]/`Arc`/`sync::Weak`. * Pairs with `from_raw_in` (which already exists on all 4 types). * Name matches `Box::into_raw_with_allocator`. * Associated fns on `Rc`/`Arc`, methods on `Weak`s. <details> <summary>Future PR/ACP</summary> As a follow-on to this PR, I plan to make a PR/ACP later to move `into_raw(_parts)` from `Container<_, A: Allocator>` to only `Container<_, Global>` (where `Container` = `Vec`/`Box`/`Rc`/`rc::Weak`/`Arc`/`sync::Weak`) so that users of non-`Global` allocators have to explicitly handle the allocator when using `into_raw`-like APIs. The current behaviors of stdlib containers are inconsistent with respect to what happens to the allocator when `into_raw` is called (which does not return the allocator) | Type | `into_raw` currently callable with | behavior of `into_raw`| | --- | --- | --- | | `Box` | any allocator | allocator is [dropped](https://doc.rust-lang.org/nightly/src/alloc/boxed.rs.html#1060) | | `Vec` | any allocator | allocator is [forgotten](https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#884) | | `Arc`/`Rc`/`Weak` | any allocator | allocator is [forgotten](https://doc.rust-lang.org/src/alloc/sync.rs.html#1487)(Arc) [(sync::Weak)](https://doc.rust-lang.org/src/alloc/sync.rs.html#2726) [(Rc)](https://doc.rust-lang.org/src/alloc/rc.rs.html#1352) [(rc::Weak)](https://doc.rust-lang.org/src/alloc/rc.rs.html#2993) | In my opinion, neither implicitly dropping nor implicitly forgetting the allocator is ideal; dropping it could immediately invalidate the returned pointer, and forgetting it could unintentionally leak memory. My (to-be) proposed solution is to just forbid calling `into_raw(_parts)` on containers with non-`Global` allocators, and require calling `into_raw_with_allocator`(/`Vec::into_raw_parts_with_alloc`) </details> [^1]: Technically, `rc::Weak::into_raw_with_allocator` is not newly added, as it was modified and renamed from `rc::Weak::into_raw_and_alloc`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-allocators
Area: Custom and system allocators
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
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.
Split out from #119761
Add
fn into_raw_with_allocator
forRc
/rc::Weak
1/Arc
/sync::Weak
.from_raw_in
(which already exists on all 4 types).Box::into_raw_with_allocator
.Rc
/Arc
, methods onWeak
s.Future PR/ACP
As a follow-on to this PR, I plan to make a PR/ACP later to move
into_raw(_parts)
fromContainer<_, A: Allocator>
to onlyContainer<_, Global>
(whereContainer
=Vec
/Box
/Rc
/rc::Weak
/Arc
/sync::Weak
) so that users of non-Global
allocators have to explicitly handle the allocator when usinginto_raw
-like APIs.The current behaviors of stdlib containers are inconsistent with respect to what happens to the allocator when
into_raw
is called (which does not return the allocator)into_raw
currently callable withinto_raw
Box
Vec
Arc
/Rc
/Weak
In my opinion, neither implicitly dropping nor implicitly forgetting the allocator is ideal; dropping it could immediately invalidate the returned pointer, and forgetting it could unintentionally leak memory. My (to-be) proposed solution is to just forbid calling
into_raw(_parts)
on containers with non-Global
allocators, and require callinginto_raw_with_allocator
(/Vec::into_raw_parts_with_alloc
)Footnotes
Technically,
rc::Weak::into_raw_with_allocator
is not newly added, as it was modified and renamed fromrc::Weak::into_raw_and_alloc
. ↩