From f04a28feecd42e5e0657bdad2a4cf0f93c9ee749 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Sat, 23 Mar 2024 19:00:16 -0400 Subject: [PATCH] Eliminate unreachable branch --- time-macros/src/format_description/format_item.rs | 11 +++-------- time/src/format_description/parse/format_item.rs | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/time-macros/src/format_description/format_item.rs b/time-macros/src/format_description/format_item.rs index b5c6d05ff..ea36caee0 100644 --- a/time-macros/src/format_description/format_item.rs +++ b/time-macros/src/format_description/format_item.rs @@ -102,14 +102,9 @@ impl From> for crate::format_description::public::OwnedFormatItem { impl<'a> From]>> for crate::format_description::public::OwnedFormatItem { fn from(items: Box<[Item<'a>]>) -> Self { let items = items.into_vec(); - if items.len() == 1 { - if let Ok([item]) = <[_; 1]>::try_from(items) { - item.into() - } else { - bug!("the length was just checked to be 1") - } - } else { - Self::Compound(items.into_iter().map(Self::from).collect()) + match <[_; 1]>::try_from(items) { + Ok([item]) => item.into(), + Err(vec) => Self::Compound(vec.into_iter().map(Into::into).collect()), } } } diff --git a/time/src/format_description/parse/format_item.rs b/time/src/format_description/parse/format_item.rs index 3199b079b..2e1ee6a74 100644 --- a/time/src/format_description/parse/format_item.rs +++ b/time/src/format_description/parse/format_item.rs @@ -149,14 +149,9 @@ impl From> for crate::format_description::OwnedFormatItem { impl<'a> From]>> for crate::format_description::OwnedFormatItem { fn from(items: Box<[Item<'a>]>) -> Self { let items = items.into_vec(); - if items.len() == 1 { - if let Ok([item]) = <[_; 1]>::try_from(items) { - item.into() - } else { - bug!("the length was just checked to be 1") - } - } else { - Self::Compound(items.into_iter().map(Self::from).collect()) + match <[_; 1]>::try_from(items) { + Ok([item]) => item.into(), + Err(vec) => Self::Compound(vec.into_iter().map(Into::into).collect()), } } }