The documentation of `Arc`'s `Weak::upgrade` does not mention dissosiation
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
Location (URL)
https://doc.rust-lang.org/std/sync/struct.Weak.html#method.upgrade
Summary
The documentation says:
Attempts to upgrade the Weak pointer to an Arc, delaying dropping of the inner value if successful.
Returns None if the inner value has since been dropped.
It is possible that the value is not dropped, but the Weak reference is dissosiated due to the call to Arc::make_mute and upgrade would still return None:
use std::sync::Arc;
fn main() {
let mut r = Arc::new(S { num: 5 });
println!("Having {}", r.num);
let wr = Arc::downgrade(&r);
let s = Arc::make_mut(&mut r);
s.num += 1;
assert!(wr.upgrade().is_none());
}
#[derive(Debug)]
pub struct S {
pub num: i32,
}
impl Clone for S {
fn clone(&self) -> Self {
Self { num: self.num }
}
}
impl Drop for S {
fn drop(&mut self) {
println!("Dropping {}", self.num);
}
}
Should it be mentioned in the documentation of Weak::upgrade that it may return None for dessosiated references which does not necessarily imply dropping?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the documented Arc::Weak::upgrade entry point in the linked standard-library URL and compare its wording with the Arc::make_mut behavior shown in the issue. Done means the documentation explains that dissociated Weak references can make upgrade return None even when the inner value has not been dropped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100