@@ -234,7 +234,8 @@ impl<'a, T: ?Sized> Box<'a, T> {
234234 /// ```
235235 #[ inline]
236236 pub unsafe fn from_raw ( raw : * mut T ) -> Self {
237- // Safety - The preconditions of the unsafe from_raw function ensure raw is valid
237+ // Safety: part of this function's unsafe contract is that the raw
238+ // pointer be non-null.
238239 Box ( unsafe { NonNull :: new_unchecked ( raw) } , PhantomData )
239240 }
240241
@@ -551,15 +552,16 @@ impl<'a, T: ?Sized> fmt::Pointer for Box<'a, T> {
551552 }
552553}
553554
554- //This function tests that box isn't contravariant.
555+ ///This function tests that box isn't contravariant.
556+ ///
555557/// ```compile_fail
556558/// fn _box_is_not_contravariant<'sub, 'sup :'sub>(
557- /// a: Box<&'sup u32>,
558- /// b: Box<&'sub u32>,
559- /// f: impl Fn(Box<&'sup u32>),
559+ /// a: Box<&'sup u32>,
560+ /// b: Box<&'sub u32>,
561+ /// f: impl Fn(Box<&'sup u32>),
560562/// ) {
561- /// f(a);
562- /// f(b);
563+ /// f(a);
564+ /// f(b);
563565/// }
564566/// ```
565567#[ cfg( doctest) ]
@@ -569,14 +571,18 @@ impl<'a, T: ?Sized> Deref for Box<'a, T> {
569571 type Target = T ;
570572
571573 fn deref ( & self ) -> & T {
572- // Safety - The box points to a valid instance of T allocated with a Bumpalo arena.
574+ // Safety: Our pointer always points to a valid instance of `T`
575+ // allocated within a `Bump` and the `&self` borrow ensures that there
576+ // are no active exclusive borrows.
573577 unsafe { self . 0 . as_ref ( ) }
574578 }
575579}
576580
577581impl < ' a , T : ?Sized > DerefMut for Box < ' a , T > {
578582 fn deref_mut ( & mut self ) -> & mut T {
579- // Safety - The box points to a valid instance of T allocated with a Bumpalo arena.
583+ // Safety: Our pointer always points to a valid instance of `T`
584+ // allocated within a `Bump` and the `&mut self` borrow ensures that
585+ // there are no other active borrows.
580586 unsafe { self . 0 . as_mut ( ) }
581587 }
582588}
0 commit comments