diff options
| author | bors <bors@rust-lang.org> | 2019-12-11 09:12:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-11 09:12:06 +0000 |
| commit | 033662dfbca088937b9cdfd3d9584015b5e375b2 (patch) | |
| tree | 2ef62b3f6d4746ca251307c5543a7f066ada1fa3 /src/libcore/alloc.rs | |
| parent | ddca1e09c36a6ce21d95fec1619f23ba59b69c8a (diff) | |
| parent | f6ceef546b9b008afd12fafa742783c570a18aa8 (diff) | |
| download | rust-033662dfbca088937b9cdfd3d9584015b5e375b2.tar.gz rust-033662dfbca088937b9cdfd3d9584015b5e375b2.zip | |
Auto merge of #67220 - Centril:rollup-n3u9wd5, r=Centril
Rollup of 6 pull requests Successful merges: - #66881 (Optimize Ord trait implementation for bool) - #67015 (Fix constant propagation for scalar pairs) - #67074 (Add options to --extern flag.) - #67164 (Ensure that panicking in constants eventually errors) - #67174 (Remove `checked_add` in `Layout::repeat`) - #67205 (Make `publish_toolstate.sh` executable) Failed merges: r? @ghost
Diffstat (limited to 'src/libcore/alloc.rs')
| -rw-r--r-- | src/libcore/alloc.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 4cfd6527deb..5c24e3d8f5d 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -239,8 +239,11 @@ impl Layout { #[unstable(feature = "alloc_layout_extra", issue = "55724")] #[inline] pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> { - let padded_size = self.size().checked_add(self.padding_needed_for(self.align())) - .ok_or(LayoutErr { private: () })?; + // This cannot overflow. Quoting from the invariant of Layout: + // > `size`, when rounded up to the nearest multiple of `align`, + // > must not overflow (i.e., the rounded value must be less than + // > `usize::MAX`) + let padded_size = self.size() + self.padding_needed_for(self.align()); let alloc_size = padded_size.checked_mul(n) .ok_or(LayoutErr { private: () })?; |
