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.
There was a problem hiding this comment.
There's also the unstable case of a
Weakcreated fromUniqueRc::downgradewhere theUniqueRchasn't yet been turned into anRc, for which the inner value hasn't been dropped or moved out, but something else currently owns it.
I suppose the same goes for the upgrades from within the new_cyclic callback. Should it become a list at this point?
Returns [None] in the following cases:
- the inner value has since been dropped or moved out
- this
Weakdoes not point to an allocation- the owning reference this
Weakis assosiated with is either not fully constructed or does not allow an upgrade.
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I'm not sure what tidy does not like now. |
|
You can run The specific issue here is that there is trailing whitespace on those lines. You can use You can also install a git hook so that git will error if you try to push code that fails tidy: https://rustc-dev-guide.rust-lang.org/building/suggested.html#installing-a-pre-push-hook |
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.