]> git.lizzy.rs Git - rust.git/commitdiff
Apply suggestions from code review
authorTim Diekmann <21277928+TimDiekmann@users.noreply.github.com>
Mon, 3 Aug 2020 22:21:05 +0000 (00:21 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Aug 2020 22:21:05 +0000 (00:21 +0200)
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
library/core/src/alloc/mod.rs

index 8061cb3e1722a1409bcd3e80f7ac68202d2fb852..9ab5352c1dd098cb81c172ec5845c3fbf4347924 100644 (file)
@@ -117,7 +117,7 @@ pub unsafe trait AllocRef {
     /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
     fn alloc(&mut self, layout: Layout) -> Result<MemoryBlock, AllocErr>;
 
-    /// Behaves like `alloc`, but also ensures that the contents are set to zero before being returned.
+    /// Behaves like `alloc`, but also ensures that the returned memory is zero-initialized.
     ///
     /// # Errors
     ///
@@ -156,7 +156,7 @@ fn alloc_zeroed(&mut self, layout: Layout) -> Result<MemoryBlock, AllocErr> {
     /// memory. The pointer is suitable for holding data described by a new layout with `layout`’s
     /// alignment and a size given by `new_size`. To accomplish this, the allocator may extend the
     /// allocation referenced by `ptr` to fit the new layout.
-    ///~
+    ///
     /// If this method returns `Err`, then ownership of the memory block has not been transferred to
     /// this allocator, and the contents of the memory block are unaltered.
     ///
@@ -164,12 +164,11 @@ fn alloc_zeroed(&mut self, layout: Layout) -> Result<MemoryBlock, AllocErr> {
     ///
     /// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
     /// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.),
-    // We can't require that `new_size` is strictly greater than `memory.size` because of ZSTs.
-    // An alternative would be
-    // * `new_size must be strictly greater than `memory.size` or both are zero
     /// * `new_size` must be greater than or equal to `layout.size()`, and
     /// * `new_size`, when rounded up to the nearest multiple of `layout.align()`, must not overflow
     ///   (i.e., the rounded value must be less than or equal to `usize::MAX`).
+    // Note: We can't require that `new_size` is strictly greater than `layout.size()` because of ZSTs.
+    // alternative: `new_size must be strictly greater than `layout.size()` or both are zero
     ///
     /// [*currently allocated*]: #currently-allocated-memory
     /// [*fit*]: #memory-fitting
@@ -283,7 +282,7 @@ unsafe fn grow_zeroed(
             // SAFETY: the caller must ensure that the `new_size` does not overflow.
             // `layout.align()` comes from a `Layout` and is thus guaranteed to be valid for a Layout.
             // The caller must ensure that `new_size` is greater than or equal to zero. If it's equal
-            // to zero, it's catched beforehand.
+            // to zero, it's caught beforehand.
             unsafe { Layout::from_size_align_unchecked(new_size, layout.align()) };
         let new_memory = self.alloc_zeroed(new_layout)?;