Skip to content

Commit

Permalink
Error on missing component in match
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Aug 28, 2023
1 parent bb9b38e commit 281aae7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion time/src/formatting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}

Expand Down

0 comments on commit 281aae7

Please sign in to comment.