summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-12-03 01:50:33 +0000
committerbors <bors@rust-lang.org>2019-12-03 01:50:33 +0000
commit4787e97475de6be9487e3d9255a9c2d3c0bf9252 (patch)
tree1392d3c24ff90ef3424c873bd51b4cca055c6c62 /src/liballoc
parentfdc0011561c6365c596dfd8fa1ef388162bc89c7 (diff)
parentd1e53da80992d27073b3e918bd56d6c0692f160c (diff)
downloadrust-4787e97475de6be9487e3d9255a9c2d3c0bf9252.tar.gz
rust-4787e97475de6be9487e3d9255a9c2d3c0bf9252.zip
Auto merge of #66256 - CAD97:patch-2, r=RalfJung
Layout::pad_to_align is infallible

As per [this comment](https://github.com/rust-lang/rust/issues/55724#issuecomment-441421651) (cc @glandium).

> Per https://github.com/rust-lang/rust/blob/eb981a1/src/libcore/alloc.rs#L63-L65, `layout.size()` is always <= `usize::MAX - (layout.align() - 1)`.
>
> Which means:
>
> * The maximum value `layout.size()` can have is already aligned for `layout.align()` (`layout.align()` being a power of two, `usize::MAX - (layout.align() - 1)` is a multiple of `layout.align()`)
> * Incidentally, any value smaller than that maximum value will align at most to that maximum value.
>
> IOW, `pad_to_align` can not return `Err(LayoutErr)`, except for the layout not respecting its invariants, but we shouldn't care about that.

This PR makes `pad_to_align` return `Layout` directly, representing the fact that it cannot fail.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/rc.rs2
-rw-r--r--src/liballoc/sync.rs2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index ec08965674a..2254cde7f49 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -926,7 +926,7 @@ impl<T: ?Sized> Rc<T> {
         // reference (see #54908).
         let layout = Layout::new::<RcBox<()>>()
             .extend(value_layout).unwrap().0
-            .pad_to_align().unwrap();
+            .pad_to_align();
 
         // Allocate for the layout.
         let mem = Global.alloc(layout)
diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs
index 0deb321d623..7bf2ff13615 100644
--- a/src/liballoc/sync.rs
+++ b/src/liballoc/sync.rs
@@ -780,7 +780,7 @@ impl<T: ?Sized> Arc<T> {
         // reference (see #54908).
         let layout = Layout::new::<ArcInner<()>>()
             .extend(value_layout).unwrap().0
-            .pad_to_align().unwrap();
+            .pad_to_align();
 
         let mem = Global.alloc(layout)
             .unwrap_or_else(|_| handle_alloc_error(layout));