Skip to content

Commit 09d937e

Browse files
committed
Add comment explaining why we use NonNull
1 parent fa1656e commit 09d937e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

library/std/src/sync/rwlock.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ unsafe impl<T: ?Sized + Send + Sync> Sync for RwLock<T> {}
102102
#[stable(feature = "rust1", since = "1.0.0")]
103103
#[clippy::has_significant_drop]
104104
pub struct RwLockReadGuard<'a, T: ?Sized + 'a> {
105+
// NB: we use a pointer instead of `&'a T` to avoid `noalias` violations, because a
106+
// `Ref` argument doesn't hold immutability for its whole scope, only until it drops.
107+
// `NonNull` is also covariant over `T`, just like we would have with `&T`. `NonNull`
108+
// is preferable over `const* T` to allow for niche optimization.
105109
data: NonNull<T>,
106110
inner_lock: &'a sys::MovableRwLock,
107111
}

0 commit comments

Comments
 (0)