Skip to content

Commit 70650f8

Browse files
committed
Document that Unique<T> and Shared<T> are non-null
1 parent c007e4a commit 70650f8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/libcore/ptr.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl<T: ?Sized> PartialOrd for *mut T {
465465
fn ge(&self, other: &*mut T) -> bool { *self >= *other }
466466
}
467467

468-
/// A wrapper around a raw `*mut T` that indicates that the possessor
468+
/// A wrapper around a raw non-null `*mut T` that indicates that the possessor
469469
/// of this wrapper owns the referent. This in turn implies that the
470470
/// `Unique<T>` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a raw
471471
/// `*mut T` (which conveys no particular ownership semantics). It
@@ -502,6 +502,10 @@ unsafe impl<T: Sync + ?Sized> Sync for Unique<T> { }
502502
#[unstable(feature = "unique", issue = "27730")]
503503
impl<T: ?Sized> Unique<T> {
504504
/// Creates a new `Unique`.
505+
///
506+
/// # Safety
507+
///
508+
/// `ptr` must be non-null.
505509
pub const unsafe fn new(ptr: *mut T) -> Unique<T> {
506510
Unique { pointer: NonZero::new(ptr), _marker: PhantomData }
507511
}
@@ -537,7 +541,7 @@ impl<T> fmt::Pointer for Unique<T> {
537541
}
538542
}
539543

540-
/// A wrapper around a raw `*mut T` that indicates that the possessor
544+
/// A wrapper around a raw non-null `*mut T` that indicates that the possessor
541545
/// of this wrapper has shared ownership of the referent. Useful for
542546
/// building abstractions like `Rc<T>` or `Arc<T>`, which internally
543547
/// use raw pointers to manage the memory that they own.
@@ -566,6 +570,10 @@ impl<T: ?Sized> !Sync for Shared<T> { }
566570
#[unstable(feature = "shared", issue = "27730")]
567571
impl<T: ?Sized> Shared<T> {
568572
/// Creates a new `Shared`.
573+
///
574+
/// # Safety
575+
///
576+
/// `ptr` must be non-null.
569577
pub unsafe fn new(ptr: *mut T) -> Self {
570578
Shared { pointer: NonZero::new(ptr), _marker: PhantomData }
571579
}

0 commit comments

Comments
 (0)