Documenting the case of Weak::upgrade returning None when the value behind the reference is missing#155049
Conversation
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
library/alloc/src/rc.rs
Outdated
| /// dropping of the inner value if successful. | ||
| /// | ||
| /// Returns [`None`] if the inner value has since been dropped. | ||
| /// Returns [`None`] if the inner value has since been dropped or moved out. |
There was a problem hiding this comment.
Technically, there is a third nightly-only case for Weak::upgrade returning None for Rc when the reference has been created by calling new_in, but I'm not sure how and whether it should be explicitely mentioned.
There was a problem hiding this comment.
new_in is the allocator_api analogue of the stable Weak::new, for which upgrade has the same behavior.
Maybe something like
Returns [
None] if the inner value has since been dropped or moved out, or if thisWeakdoes not point to an allocation.
There was a problem hiding this comment.
There's also the unstable case of a Weak created from UniqueRc::downgrade where the UniqueRc hasn't yet been turned into an Rc, for which the inner value hasn't been dropped or moved out, but something else currently owns it.
Weak::upgrade when the value behind the reference has been moved outWeak::upgrade returning None when the value behind the reference has been moved out
Based on PR comments
Based on PR's comments
Weak::upgrade returning None when the value behind the reference has been moved outWeak::upgrade returning None when the value behind the reference is missing
Adds a clause to the documentation of
WeakforArcwhich was discussed in #154936.Adds the same clause to the documentation of
WeakforRc, because the behavior is the same.