From 0c011dea8b3f9b5aad42a685b8b971f60a46be7b Mon Sep 17 00:00:00 2001 From: LingMan Date: Fri, 21 Apr 2023 23:09:51 +0200 Subject: [PATCH] Mark `SecondsFormat` as #[non_exhaustive] Removes the current hack and replaces it with the proper attribute that's available since Rust 1.45. Co-developed-by: TennyZhuang --- src/datetime/mod.rs | 8 +------- src/datetime/tests.rs | 8 -------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 8f84ab1b..abe623bb 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -47,6 +47,7 @@ mod tests; /// future, so exhaustive matching in external code is not recommended. /// /// See the `TimeZone::to_rfc3339_opts` function for usage. +#[non_exhaustive] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub enum SecondsFormat { /// Format whole seconds only, with no decimal point nor subseconds. @@ -68,10 +69,6 @@ pub enum SecondsFormat { /// display all available non-zero sub-second digits. This corresponds to /// [Fixed::Nanosecond](format/enum.Fixed.html#variant.Nanosecond). AutoSi, - - // Do not match against this. - #[doc(hidden)] - __NonExhaustive, } /// ISO 8601 combined date and time with time zone. @@ -699,8 +696,6 @@ where use crate::format::Pad::Zero; use crate::SecondsFormat::*; - debug_assert!(secform != __NonExhaustive, "Do not use __NonExhaustive!"); - const PREFIX: &[Item<'static>] = &[ Item::Numeric(Year, Zero), Item::Literal("-"), @@ -721,7 +716,6 @@ where Micros => Some(Item::Fixed(Fixed::Nanosecond6)), Nanos => Some(Item::Fixed(Fixed::Nanosecond9)), AutoSi => Some(Item::Fixed(Fixed::Nanosecond)), - __NonExhaustive => unreachable!(), }; let tzitem = Item::Fixed(if use_z { diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index 3e8a871f..f81f8744 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -693,14 +693,6 @@ fn test_rfc3339_opts() { assert_eq!(ut.to_rfc3339_opts(AutoSi, true), "2018-01-11T02:05:13.084660Z"); } -#[test] -#[should_panic] -fn test_rfc3339_opts_nonexhaustive() { - use crate::SecondsFormat; - let dt = Utc.with_ymd_and_hms(1999, 10, 9, 1, 2, 3).unwrap(); - dt.to_rfc3339_opts(SecondsFormat::__NonExhaustive, true); -} - #[test] fn test_datetime_from_str() { assert_eq!(