File tree 2 files changed +4
-4
lines changed
2 files changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -1899,7 +1899,7 @@ impl<T: ?Sized> Weak<T> {
1899
1899
// a valid pointer, so that `from_raw` can reverse this transformation.
1900
1900
( ptr as * mut T ) . set_ptr_value ( ptr:: null_mut ( ) )
1901
1901
} else {
1902
- // SAFETY: If the pointer is not dangling, it references a valid allocation .
1902
+ // SAFETY: if is_dangling returns false, then the pointer is dereferencable .
1903
1903
// The payload may be dropped at this point, and we have to maintain provenance,
1904
1904
// so use raw pointer manipulation.
1905
1905
unsafe { & raw mut ( * ptr) . value }
@@ -1991,7 +1991,7 @@ impl<T: ?Sized> Weak<T> {
1991
1991
// SAFETY: this is the same sentinel as used in Weak::new and is_dangling
1992
1992
( ptr as * mut RcBox < T > ) . set_ptr_value ( usize:: MAX as * mut _ )
1993
1993
} else {
1994
- // Otherwise, this references a real allocation .
1994
+ // Otherwise, we're guaranteed the pointer came from a nondangling Weak .
1995
1995
// SAFETY: data_offset is safe to call, as ptr references a real (potentially dropped) T.
1996
1996
let offset = unsafe { data_offset ( ptr) } ;
1997
1997
// Thus, we reverse the offset to get the whole RcBox.
Original file line number Diff line number Diff line change @@ -1685,7 +1685,7 @@ impl<T: ?Sized> Weak<T> {
1685
1685
// a valid pointer, so that `from_raw` can reverse this transformation.
1686
1686
( ptr as * mut T ) . set_ptr_value ( ptr:: null_mut ( ) )
1687
1687
} else {
1688
- // SAFETY: If the pointer is not dangling, it references a valid allocation .
1688
+ // SAFETY: if is_dangling returns false, then the pointer is dereferencable .
1689
1689
// The payload may be dropped at this point, and we have to maintain provenance,
1690
1690
// so use raw pointer manipulation.
1691
1691
unsafe { & raw mut ( * ptr) . data }
@@ -1777,7 +1777,7 @@ impl<T: ?Sized> Weak<T> {
1777
1777
// SAFETY: this is the same sentinel as used in Weak::new and is_dangling
1778
1778
( ptr as * mut ArcInner < T > ) . set_ptr_value ( usize:: MAX as * mut _ )
1779
1779
} else {
1780
- // Otherwise, this references a real allocation .
1780
+ // Otherwise, we're guaranteed the pointer came from a nondangling Weak .
1781
1781
// SAFETY: data_offset is safe to call, as ptr references a real (potentially dropped) T.
1782
1782
let offset = unsafe { data_offset ( ptr) } ;
1783
1783
// Thus, we reverse the offset to get the whole RcBox.
You can’t perform that action at this time.
0 commit comments