Skip to content
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

Merged
merged 7 commits into from Dec 30, 2015
Merged

Implement Weak::new_downgraded() (#30425) #30467

merged 7 commits into from Dec 30, 2015

Conversation

@shahn
Copy link
Contributor

@shahn shahn commented Dec 18, 2015

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.
@rust-highfive
Copy link
Collaborator

@rust-highfive rust-highfive commented Dec 18, 2015

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.

@brson
Copy link
Contributor

@brson brson commented Dec 18, 2015

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(),

This comment has been minimized.

@apasel422

apasel422 Dec 18, 2015
Contributor

Can this use core::mem::uninitialized instead?

This comment has been minimized.

@shahn

shahn Dec 18, 2015
Author Contributor

fixing

@alexcrichton
Copy link
Member

@alexcrichton alexcrichton commented Dec 18, 2015

I would probably personally call this Weak::new to stick closer to our existing conventions, but otherwise it seems harmless to me as well.

@apasel422
Copy link
Contributor

@apasel422 apasel422 commented Dec 18, 2015

Should Arc's Weak have this as well?

@shahn
Copy link
Contributor Author

@shahn shahn commented Dec 18, 2015

@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.

@alexcrichton alexcrichton added the T-libs label Dec 18, 2015
@shahn
Copy link
Contributor Author

@shahn shahn commented Dec 18, 2015

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);

This comment has been minimized.

@apasel422

apasel422 Dec 18, 2015
Contributor

This should be Weak::new.

///
/// use std::rc::Weak;
///
/// let empty:Weak<i64> = Weak::new();

This comment has been minimized.

@apasel422

apasel422 Dec 18, 2015
Contributor

There should be a space before Weak<i64>.

issue = "30425")]
pub fn new() -> Weak<T> {
unsafe {
let x: Box<_> = box ArcInner {

This comment has been minimized.

@apasel422

apasel422 Dec 18, 2015
Contributor

Is there a reason this Box is assigned to a local variable when the one for rc::Weak isn't?

This comment has been minimized.

@shahn

shahn Dec 19, 2015
Author Contributor

I mirrored Arc::new(). But I can remove it.

@sfackler

This comment has been minimized.

Copy link

@sfackler sfackler commented on src/liballoc/rc.rs in 79d0235 Dec 19, 2015

five?

@sfackler

This comment has been minimized.

Copy link

@sfackler sfackler commented on src/liballoc/rc.rs in 79d0235 Dec 19, 2015

Not sure how valuable an example that does nothing but call the method is.

@shahn
Copy link
Contributor Author

@shahn shahn commented Dec 19, 2015

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?

@shahn
Copy link
Contributor Author

@shahn shahn commented Dec 20, 2015

I think I addressed all review comments, thanks a bunch. Anything else for me to do except wait while a decision is made?

@brson
Copy link
Contributor

@brson brson commented Dec 28, 2015

@bors r+

@bors
Copy link
Contributor

@bors bors commented Dec 28, 2015

📌 Commit 5b3bdaf has been approved by brson

Manishearth added a commit to Manishearth/rust that referenced this pull request Dec 29, 2015
This adds a constructor for a Weak that can never be upgraded. These are
mostly useless, but for example are required when deserializing.
@bors
Copy link
Contributor

@bors bors commented Dec 30, 2015

Testing commit 5b3bdaf with merge cb50f54...

bors added a commit that referenced this pull request Dec 30, 2015
This adds a constructor for a Weak that can never be upgraded. These are
mostly useless, but for example are required when deserializing.
@bors
Copy link
Contributor

@bors bors commented Dec 30, 2015

💔 Test failed - auto-linux-64-nopt-t

@sfackler
Copy link
Member

@sfackler sfackler commented Dec 30, 2015

@bors retry

bors added a commit that referenced this pull request Dec 30, 2015
This adds a constructor for a Weak that can never be upgraded. These are
mostly useless, but for example are required when deserializing.
@bors
Copy link
Contributor

@bors bors commented Dec 30, 2015

Testing commit 5b3bdaf with merge 682cfc5...

@bors bors merged commit 5b3bdaf into rust-lang:master Dec 30, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants