diff options
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/allocator.rs | 46 | ||||
| -rw-r--r-- | src/liballoc/btree/set.rs | 14 | ||||
| -rw-r--r-- | src/liballoc/string.rs | 5 | ||||
| -rw-r--r-- | src/liballoc/vec.rs | 5 |
4 files changed, 15 insertions, 55 deletions
diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs index 3a2022ad429..c2a8f5f8ff9 100644 --- a/src/liballoc/allocator.rs +++ b/src/liballoc/allocator.rs @@ -217,14 +217,8 @@ impl Layout { /// On arithmetic overflow, returns `None`. #[inline] pub fn repeat(&self, n: usize) -> Option<(Self, usize)> { - let padded_size = match self.size.checked_add(self.padding_needed_for(self.align)) { - None => return None, - Some(padded_size) => padded_size, - }; - let alloc_size = match padded_size.checked_mul(n) { - None => return None, - Some(alloc_size) => alloc_size, - }; + let padded_size = self.size.checked_add(self.padding_needed_for(self.align))?; + let alloc_size = padded_size.checked_mul(n)?; // We can assume that `self.align` is a power-of-two that does // not exceed 2<sup>31</sup>. Furthermore, `alloc_size` has already been @@ -246,26 +240,14 @@ impl Layout { /// On arithmetic overflow, returns `None`. pub fn extend(&self, next: Self) -> Option<(Self, usize)> { let new_align = cmp::max(self.align, next.align); - let realigned = match Layout::from_size_align(self.size, new_align) { - None => return None, - Some(l) => l, - }; + let realigned = Layout::from_size_align(self.size, new_align)?; let pad = realigned.padding_needed_for(next.align); - let offset = match self.size.checked_add(pad) { - None => return None, - Some(offset) => offset, - }; - let new_size = match offset.checked_add(next.size) { - None => return None, - Some(new_size) => new_size, - }; + let offset = self.size.checked_add(pad)?; + let new_size = offset.checked_add(next.size)?; - let layout = match Layout::from_size_align(new_size, new_align) { - None => return None, - Some(l) => l, - }; + let layout = Layout::from_size_align(new_size, new_align)?; Some((layout, offset)) } @@ -282,11 +264,7 @@ impl Layout { /// /// On arithmetic overflow, returns `None`. pub fn repeat_packed(&self, n: usize) -> Option<Self> { - let size = match self.size().checked_mul(n) { - None => return None, - Some(scaled) => scaled, - }; - + let size = self.size().checked_mul(n)?; Layout::from_size_align(size, self.align) } @@ -306,14 +284,8 @@ impl Layout { /// /// On arithmetic overflow, returns `None`. pub fn extend_packed(&self, next: Self) -> Option<(Self, usize)> { - let new_size = match self.size().checked_add(next.size()) { - None => return None, - Some(new_size) => new_size, - }; - let layout = match Layout::from_size_align(new_size, self.align) { - None => return None, - Some(l) => l, - }; + let new_size = self.size().checked_add(next.size())?; + let layout = Layout::from_size_align(new_size, self.align)?; Some((layout, self.size())) } diff --git a/src/liballoc/btree/set.rs b/src/liballoc/btree/set.rs index 7da6371cc19..580d2dbb623 100644 --- a/src/liballoc/btree/set.rs +++ b/src/liballoc/btree/set.rs @@ -1067,21 +1067,15 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { - let o_cmp = match (self.a.peek(), self.b.peek()) { - (None, _) => None, - (_, None) => None, - (Some(a1), Some(b1)) => Some(a1.cmp(b1)), - }; - match o_cmp { - None => return None, - Some(Less) => { + match Ord::cmp(self.a.peek()?, self.b.peek()?) { + Less => { self.a.next(); } - Some(Equal) => { + Equal => { self.b.next(); return self.a.next(); } - Some(Greater) => { + Greater => { self.b.next(); } } diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index cd0f4a22e9c..ca493ab27e3 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1044,10 +1044,7 @@ impl String { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn pop(&mut self) -> Option<char> { - let ch = match self.chars().rev().next() { - Some(ch) => ch, - None => return None, - }; + let ch = self.chars().rev().next()?; let newlen = self.len() - ch.len_utf8(); unsafe { self.vec.set_len(newlen); diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index c29449a241e..9c7c8657716 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1423,10 +1423,7 @@ impl<T: PartialEq> Vec<T> { /// ``` #[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")] pub fn remove_item(&mut self, item: &T) -> Option<T> { - let pos = match self.iter().position(|x| *x == *item) { - Some(x) => x, - None => return None, - }; + let pos = self.iter().position(|x| *x == *item)?; Some(self.remove(pos)) } } |
