Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `downgraded_weak` (No way to construct std::rc::Weak without a strong reference) #30425
Comments
Aatch
added
A-libs
T-libs
labels
Dec 17, 2015
This comment has been minimized.
This comment has been minimized.
|
/cc @rust-lang/libs |
This comment has been minimized.
This comment has been minimized.
|
I feel like I'm missing a bit of context here - wouldn't the stored object immediately be freed since the strong reference count will be zero? |
This comment has been minimized.
This comment has been minimized.
|
@sfackler, yeah, the |
This comment has been minimized.
This comment has been minimized.
|
Seems easy enough to add. Basically Option::None. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@oli-obk It could, but wouldn't it be a bit surprising that the Default for Weak is an unusable Weak? |
This comment has been minimized.
This comment has been minimized.
|
Ah, got it. |
This comment has been minimized.
This comment has been minimized.
|
Just to be clear: an empty Weak would still allocate memory. We're all in agreement that this is the desired semantic? The alternative would be adding a sentinel state to every weak pointer that needs to be checked on every access. |
This comment has been minimized.
This comment has been minimized.
|
If you care about allocating memory for empty It sounds like a needless optimization for a rare case, and the aliasing is probably undefined behaviour without care, but it's workable if you really want it. |
This comment has been minimized.
This comment has been minimized.
|
Yes, it's fine to allocate the memory (you even want to do it to match the pre-serialization state). Having a constructor called new_* should make that clear, imo |
shahn
added a commit
to shahn/rust
that referenced
this issue
Dec 18, 2015
This comment has been minimized.
This comment has been minimized.
|
This was implemented in #30467. |
This comment has been minimized.
This comment has been minimized.
|
I think this issue needs to stay open until a stabilization decision was made |
apasel422
added
the
B-unstable
label
Feb 6, 2016
sfackler
added
the
I-nominated
label
Apr 15, 2016
bluss
changed the title
No way to construct std::rc::Weak without a strong reference
Tracking issue for `downgraded_weak` (No way to construct std::rc::Weak without a strong reference)
Apr 15, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team is also considering adding a |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Apr 29, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this issue during triage yesterday and the decision was to stabilize with the |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
May 17, 2016
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
May 17, 2016
alexcrichton
referenced this issue
May 17, 2016
Merged
std: Stabilize APIs for the 1.10 release #33699
This comment has been minimized.
This comment has been minimized.
|
Sounds OK if we make sure to explain in documentation that the created |
shahn commentedDec 17, 2015
When deserializing Weak, there's currently no clean way to handle the case that there's no strong reference anymore. Serializing doesn't have the same issue. There seem to be two solutions to this, either provide an explicit constructor that returns a Weak without using a strong reference to create it, or implementing Default for it that does the same. I prefer the former, as Default might be a bit surprising.
This would be a simple, non-backwards-incompatible change. Possible constructor name bikeshedding: Weak::new_downgraded()
Unstable APIs
Weak::new