-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement Weak::new_downgraded() (#30425) #30467
Conversation
This adds a constructor for a Weak that can never be upgraded. These are mostly useless, but for example are required when deserializing.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
cc @rust-lang/libs Is everyone cool with this? Does it need an RFC? |
_ptr: Shared::new(Box::into_raw(box RcBox { | ||
strong: Cell::new(0), | ||
weak: Cell::new(1), | ||
value: uninit(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this use core::mem::uninitialized
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixing
I would probably personally call this |
Should |
@alexcrichton The reason I went with a different name was to make it clear that this won't be usable for "normal" code. Happy to defer to you of course, extending PR. @apasei422 good point! I'll extend the PR. |
I'm thinking if everyone likes this branch I should probably rebase & squash it into a single commit? |
/// | ||
/// use std::sync::Arc; | ||
/// | ||
/// let five = Arc::new(5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be Weak::new
.
I agree wrt the examples, I added them because they were there for Rc::new and Arc::new (where they also only assign a value). Should I update this? |
I think I addressed all review comments, thanks a bunch. Anything else for me to do except wait while a decision is made? |
@bors r+ |
📌 Commit 5b3bdaf has been approved by |
This adds a constructor for a Weak that can never be upgraded. These are mostly useless, but for example are required when deserializing.
⌛ Testing commit 5b3bdaf with merge cb50f54... |
💔 Test failed - auto-linux-64-nopt-t |
@bors retry |
This adds a constructor for a Weak that can never be upgraded. These are mostly useless, but for example are required when deserializing.
This adds a constructor for a Weak that can never be upgraded. These are
mostly useless, but for example are required when deserializing.