diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 8bc0e08a4b26b..e738c29c237fa 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -1646,9 +1646,8 @@ impl<'a, T> CursorMut<'a, T> { #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn splice_after(&mut self, list: LinkedList) { unsafe { - let (splice_head, splice_tail, splice_len) = match list.detach_all_nodes() { - Some(parts) => parts, - _ => return, + let Some((splice_head, splice_tail, splice_len)) = list.detach_all_nodes() else { + return; }; let node_next = match self.current { None => self.list.head, diff --git a/library/alloc/src/raw_vec/mod.rs b/library/alloc/src/raw_vec/mod.rs index 236e33e2f450e..15b0823df9ec5 100644 --- a/library/alloc/src/raw_vec/mod.rs +++ b/library/alloc/src/raw_vec/mod.rs @@ -788,9 +788,7 @@ impl RawVecInner { elem_layout: Layout, ) -> Result<(), TryReserveError> { // SAFETY: Precondition passed to caller - let (ptr, layout) = if let Some(mem) = unsafe { self.current_memory(elem_layout) } { - mem - } else { + let Some((ptr, layout)) = (unsafe { self.current_memory(elem_layout) }) else { return Ok(()); }; diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index f5ba71c288334..64abdca32d211 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -619,16 +619,14 @@ impl String { pub fn from_utf8_lossy(v: &[u8]) -> Cow<'_, str> { let mut iter = v.utf8_chunks(); - let first_valid = if let Some(chunk) = iter.next() { - let valid = chunk.valid(); - if chunk.invalid().is_empty() { - debug_assert_eq!(valid.len(), v.len()); - return Cow::Borrowed(valid); - } - valid - } else { + let Some(chunk) = iter.next() else { return Cow::Borrowed(""); }; + let first_valid = chunk.valid(); + if chunk.invalid().is_empty() { + debug_assert_eq!(first_valid.len(), v.len()); + return Cow::Borrowed(first_valid); + } const REPLACEMENT: &str = "\u{FFFD}"; @@ -720,11 +718,10 @@ impl String { // FIXME: the function can be simplified again when #48994 is closed. let mut ret = String::with_capacity(v.len()); for c in char::decode_utf16(v.iter().cloned()) { - if let Ok(c) = c { - ret.push(c); - } else { + let Ok(c) = c else { return Err(FromUtf16Error(())); - } + }; + ret.push(c); } Ok(ret) } diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index d571e35828aeb..b08bb9cb6d191 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -112,12 +112,11 @@ impl Drain<'_, T, A> { }; for place in range_slice { - if let Some(new_item) = replace_with.next() { - unsafe { ptr::write(place, new_item) }; - vec.len += 1; - } else { + let Some(new_item) = replace_with.next() else { return false; - } + }; + unsafe { ptr::write(place, new_item) }; + vec.len += 1; } true } diff --git a/library/core/src/num/dec2flt/mod.rs b/library/core/src/num/dec2flt/mod.rs index dd4eccd24de03..eee8adf4f7554 100644 --- a/library/core/src/num/dec2flt/mod.rs +++ b/library/core/src/num/dec2flt/mod.rs @@ -255,11 +255,7 @@ fn biased_fp_to_float(x: BiasedFp) -> F { #[inline(always)] // Will be inlined into a function with `#[inline(never)]`, see above pub fn dec2flt(s: &str) -> Result { let mut s = s.as_bytes(); - let c = if let Some(&c) = s.first() { - c - } else { - return Err(pfe_empty()); - }; + let Some(&c) = s.first() else { return Err(pfe_empty()) }; let negative = c == b'-'; if c == b'-' || c == b'+' { s = &s[1..]; diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 51a01545f5cf5..b85179e925d13 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -672,11 +672,10 @@ impl Duration { let mut nanos = self.nanos.as_inner() + rhs.nanos.as_inner(); if nanos >= NANOS_PER_SEC { nanos -= NANOS_PER_SEC; - if let Some(new_secs) = secs.checked_add(1) { - secs = new_secs; - } else { + let Some(new_secs) = secs.checked_add(1) else { return None; - } + }; + secs = new_secs; } debug_assert!(nanos < NANOS_PER_SEC); Some(Duration::new(secs, nanos)) diff --git a/library/std/src/sys/pal/windows/pipe.rs b/library/std/src/sys/pal/windows/pipe.rs index d8e306068d73c..32cf4695d4a15 100644 --- a/library/std/src/sys/pal/windows/pipe.rs +++ b/library/std/src/sys/pal/windows/pipe.rs @@ -530,10 +530,7 @@ impl<'a> AsyncPipe<'a> { impl<'a> Drop for AsyncPipe<'a> { fn drop(&mut self) { - match self.state { - State::Reading => {} - _ => return, - } + let State::Reading = self.state else { return }; // If we have a pending read operation, then we have to make sure that // it's *done* before we actually drop this type. The kernel requires