Skip to content

Documenting the case of Weak::upgrade returning None when the value behind the reference is missing#155049

Open
quixoticaxis wants to merge 4 commits intorust-lang:mainfrom
quixoticaxis:weak-upgrade-documentation-extension
Open

Documenting the case of Weak::upgrade returning None when the value behind the reference is missing#155049
quixoticaxis wants to merge 4 commits intorust-lang:mainfrom
quixoticaxis:weak-upgrade-documentation-extension

Conversation

@quixoticaxis
Copy link
Copy Markdown

@quixoticaxis quixoticaxis commented Apr 9, 2026

Adds a clause to the documentation of Weak for Arc which was discussed in #154936.

Adds the same clause to the documentation of Weak for Rc, because the behavior is the same.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 9, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 7 candidates
  • Random selection from Mark-Simulacrum, jhpratt

/// 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.
Copy link
Copy Markdown
Author

@quixoticaxis quixoticaxis Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View changes since the review

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 this Weak does not point to an allocation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

@quixoticaxis quixoticaxis Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zachs18 updated the comment both for Rc and Arc.

@quixoticaxis quixoticaxis changed the title Documenting the case of Weak::upgrade when the value behind the reference has been moved out Documenting the case of Weak::upgrade returning None when the value behind the reference has been moved out Apr 9, 2026
@quixoticaxis quixoticaxis changed the title Documenting the case of Weak::upgrade returning None when the value behind the reference has been moved out Documenting the case of Weak::upgrade returning None when the value behind the reference is missing Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants