From 281aae7264fb5359b6218d66ad455af584c75ffd Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Mon, 28 Aug 2023 00:38:50 -0400 Subject: [PATCH] Error on missing component in match --- time/src/formatting/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/time/src/formatting/mod.rs b/time/src/formatting/mod.rs index b6da6b74c..20b4d0422 100644 --- a/time/src/formatting/mod.rs +++ b/time/src/formatting/mod.rs @@ -198,7 +198,18 @@ pub(crate) fn format_component( fmt_unix_timestamp(output, date, time, offset, modifier)? } (End(modifier::End {}), ..) => 0, - _ => return Err(error::Format::InsufficientTypeInformation), + + // This is functionally the same as a wildcard arm, but it will cause an error if a new + // component is added. This is to avoid a bug where a new component, the code compiles, and + // formatting fails. + // Allow unreachable patterns because some branches may be fully matched above. + #[allow(unreachable_patterns)] + ( + Day(_) | Month(_) | Ordinal(_) | Weekday(_) | WeekNumber(_) | Year(_) | Hour(_) + | Minute(_) | Period(_) | Second(_) | Subsecond(_) | OffsetHour(_) | OffsetMinute(_) + | OffsetSecond(_) | Ignore(_) | UnixTimestamp(_) | End(_), + .., + ) => return Err(error::Format::InsufficientTypeInformation), }) }