about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2021-11-26 13:36:39 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2021-11-26 19:30:35 +1100
commit026edbb4ef85ef3d38876548a771b7c72c87803f (patch)
tree6859234c043c8ae1db171f6bce7fcb94441a7a81
parent8a48b376d559f26a9b8fc1f1d597acb0bc0a51f9 (diff)
downloadrust-026edbb4ef85ef3d38876548a771b7c72c87803f.tar.gz
rust-026edbb4ef85ef3d38876548a771b7c72c87803f.zip
Use unchecked construction in `Layout::pad_to_align`.
Other, similar methods for `Layout` do likewise, and there's already an
`unwrap()` around the result demonstrating the safety.
-rw-r--r--library/core/src/alloc/layout.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs
index cc32d5223b4..a9abb8d2d59 100644
--- a/library/core/src/alloc/layout.rs
+++ b/library/core/src/alloc/layout.rs
@@ -281,7 +281,9 @@ impl Layout {
         // > `usize::MAX`)
         let new_size = self.size() + pad;
 
-        Layout::from_size_align(new_size, self.align()).unwrap()
+        // SAFETY: self.align is already known to be valid and new_size has been
+        // padded already.
+        unsafe { Layout::from_size_align_unchecked(new_size, self.align()) }
     }
 
     /// Creates a layout describing the record for `n` instances of