Skip to content

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

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
quixoticaxis:weak-upgrade-documentation-extension
Apr 17, 2026
Merged

Documenting the case of Weak::upgrade returning None when the value behind the reference is missing#155049
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
quixoticaxis:weak-upgrade-documentation-extension

Conversation

@quixoticaxis

@quixoticaxis quixoticaxis commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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

rustbot commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

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

Comment thread 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.

@quixoticaxis quixoticaxis Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

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.

@quixoticaxis quixoticaxis Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

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 Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

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.

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 Weak does not point to an allocation
  • the owning reference this Weak is assosiated with is either not fully constructed or does not allow an upgrade.

@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
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@quixoticaxis

Copy link
Copy Markdown
Contributor Author

I'm not sure what tidy does not like now.

@zachs18

zachs18 commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

You can run ./x test tidy locally, and it shows the issue highlighted with ANSI terminal color.

The specific issue here is that there is trailing whitespace on those lines.

You can use ./x test tidy --bless to remove the trailing whitespace.

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

@jhpratt

jhpratt commented Apr 17, 2026

Copy link
Copy Markdown
Member

@bors squash "Extended the documentation for Arc's Weak::upgrade"

@rust-bors

rust-bors Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Unknown argument ""Extended". Did you mean to use @bors squash [msg|message="<commit-msg>"]? Run @bors help to see available commands.

@jhpratt

jhpratt commented Apr 17, 2026

Copy link
Copy Markdown
Member

@bors squash message="Extended the documentation for Arc's Weak::upgrade"

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

🔨 7 commits were squashed into f580872.

@rust-bors rust-bors Bot force-pushed the weak-upgrade-documentation-extension branch from 2c08481 to f580872 Compare April 17, 2026 07:47
@jhpratt

jhpratt commented Apr 17, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit f580872 has been approved by jhpratt

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 17, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 17, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #154781 (Fix attribute order implementation)
 - #155242 (resolve: Introduce `(Local,Extern)Module` newtypes for local and external modules respectively)
 - #149614 (Use `MaybeDangling` in `std`)
 - #153178 (Add `TryFromIntError::kind` method and `IntErrorKind::NotAPowerOfTwo` variant)
 - #155049 (Documenting the case of `Weak::upgrade` returning `None` when the value behind the reference is missing)

Failed merges:

 - #155308 (Make `OnDuplicate::Error` the default for attributes)
rust-bors Bot pushed a commit that referenced this pull request Apr 17, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #154781 (Fix attribute order implementation)
 - #155242 (resolve: Introduce `(Local,Extern)Module` newtypes for local and external modules respectively)
 - #149614 (Use `MaybeDangling` in `std`)
 - #153178 (Add `TryFromIntError::kind` method and `IntErrorKind::NotAPowerOfTwo` variant)
 - #155049 (Documenting the case of `Weak::upgrade` returning `None` when the value behind the reference is missing)

Failed merges:

 - #155308 (Make `OnDuplicate::Error` the default for attributes)
rust-timer added a commit that referenced this pull request Apr 17, 2026
Rollup merge of #155049 - quixoticaxis:weak-upgrade-documentation-extension, r=jhpratt

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

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.
@rust-bors rust-bors Bot merged commit f67a375 into rust-lang:main Apr 17, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants