Skip to content

Commit 7498cad

Browse files
committed
Reclarify safety comments in Weak::as_ptr
1 parent 98789ac commit 7498cad

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/liballoc/rc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1705,9 +1705,9 @@ impl<T> Weak<T> {
17051705
let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr);
17061706

17071707
// SAFETY: we must offset the pointer manually, and said pointer may be
1708-
// a dangling weak (usize::MAX). data_offset is safe to call, because we
1709-
// know a pointer to unsized T must be derived from a real unsized T,
1710-
// because dangling weaks are only created for sized T. wrapping_offset
1708+
// a dangling weak (usize::MAX) if T is sized. data_offset is safe to call,
1709+
// because we know that a pointer to unsized T was derived from a real
1710+
// unsized T, as dangling weaks are only created for sized T. wrapping_offset
17111711
// is used so that we can use the same code path for the non-dangling
17121712
// unsized case and the potentially dangling sized case.
17131713
unsafe {

src/liballoc/sync.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1473,9 +1473,9 @@ impl<T> Weak<T> {
14731473
let ptr: *mut ArcInner<T> = NonNull::as_ptr(self.ptr);
14741474

14751475
// SAFETY: we must offset the pointer manually, and said pointer may be
1476-
// a dangling weak (usize::MAX). data_offset is safe to call, because we
1477-
// know a pointer to unsized T must be derived from a real unsized T,
1478-
// because dangling weaks are only created for sized T. wrapping_offset
1476+
// a dangling weak (usize::MAX) if T is sized. data_offset is safe to call,
1477+
// because we know that a pointer to unsized T was derived from a real
1478+
// unsized T, as dangling weaks are only created for sized T. wrapping_offset
14791479
// is used so that we can use the same code path for the non-dangling
14801480
// unsized case and the potentially dangling sized case.
14811481
unsafe {

0 commit comments

Comments
 (0)