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?
Location (URL)
https://doc.rust-lang.org/std/sync/struct.Weak.html#method.upgrade
Summary
The documentation says:
It is possible that the value is not dropped, but the
Weakreference is dissosiated due to the call toArc::make_muteand upgrade would still returnNone:Should it be mentioned in the documentation of
Weak::upgradethat it may returnNonefor dessosiated references which does not necessarily imply dropping?