Skip to content

Commit

Permalink
Statically prove uninhabitedness
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Dec 15, 2024
1 parent 16b436b commit dad76cb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ unwrap-in-result = "warn"
unwrap-used = "warn"
use-debug = "warn"

option-if-let-else = { level = "allow", priority = 1 } # suggests terrible code, overrides #![warn(clippy::nursery)]
redundant-pub-crate = { level = "allow", priority = 1 } # rust-lang/rust-clippy#5369, overrides #![warn(clippy::nursery)]
option-if-let-else = { level = "allow", priority = 1 } # suggests terrible code, overrides #![warn(clippy::nursery)]
redundant-pub-crate = { level = "allow", priority = 1 } # rust-lang/rust-clippy#5369, overrides #![warn(clippy::nursery)]
uninhabited-references = { level = "allow", priority = 1 } # rust-lang/rust-clippy#11984

[workspace.lints.rustdoc]
private-doc-tests = "warn"
Expand Down
13 changes: 7 additions & 6 deletions time/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod parse_from_description;
#[cfg(feature = "parsing")]
mod try_from_parsed;

use core::convert::Infallible;
use core::fmt;

pub use component_range::ComponentRange;
Expand All @@ -36,9 +37,6 @@ pub use parse_from_description::ParseFromDescription;
#[cfg(feature = "parsing")]
pub use try_from_parsed::TryFromParsed;

#[cfg(feature = "parsing")]
use crate::internal_macros::bug;

/// A unified error type for anything returned by a method in the time crate.
///
/// This can be used when you either don't know or don't care about the exact error returned.
Expand Down Expand Up @@ -66,7 +64,10 @@ pub enum Error {
since = "0.3.28",
note = "no longer output. moved to the `ParseFromDescription` variant"
)]
UnexpectedTrailingCharacters,
UnexpectedTrailingCharacters {
#[doc(hidden)]
never: Infallible,
},
#[cfg(feature = "parsing")]
#[allow(missing_docs)]
TryFromParsed(TryFromParsed),
Expand All @@ -92,7 +93,7 @@ impl fmt::Display for Error {
Self::ParseFromDescription(e) => e.fmt(f),
#[cfg(feature = "parsing")]
#[allow(deprecated)]
Self::UnexpectedTrailingCharacters => bug!("variant should not be used"),
Self::UnexpectedTrailingCharacters { never } => match *never {},
#[cfg(feature = "parsing")]
Self::TryFromParsed(e) => e.fmt(f),
#[cfg(all(any(feature = "formatting", feature = "parsing"), feature = "alloc"))]
Expand All @@ -117,7 +118,7 @@ impl std::error::Error for Error {
Self::ParseFromDescription(err) => Some(err),
#[cfg(feature = "parsing")]
#[allow(deprecated)]
Self::UnexpectedTrailingCharacters => bug!("variant should not be used"),
Self::UnexpectedTrailingCharacters { never } => match *never {},
#[cfg(feature = "parsing")]
Self::TryFromParsed(err) => Some(err),
#[cfg(all(any(feature = "formatting", feature = "parsing"), feature = "alloc"))]
Expand Down
17 changes: 10 additions & 7 deletions time/src/error/parse.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Error that occurred at some stage of parsing
use core::convert::Infallible;
use core::fmt;

use crate::error::{self, ParseFromDescription, TryFromParsed};
use crate::internal_macros::bug;

/// An error that occurred at some stage of parsing.
#[non_exhaustive]
Expand All @@ -13,13 +13,16 @@ pub enum Parse {
TryFromParsed(TryFromParsed),
#[allow(missing_docs)]
ParseFromDescription(ParseFromDescription),
/// The input should have ended, but there were characters remaining.
#[allow(missing_docs)]
#[non_exhaustive]
#[deprecated(
since = "0.3.28",
note = "no longer output. moved to the `ParseFromDescription` variant"
)]
UnexpectedTrailingCharacters,
UnexpectedTrailingCharacters {
#[doc(hidden)]
never: Infallible,
},
}

impl fmt::Display for Parse {
Expand All @@ -28,7 +31,7 @@ impl fmt::Display for Parse {
Self::TryFromParsed(err) => err.fmt(f),
Self::ParseFromDescription(err) => err.fmt(f),
#[allow(deprecated)]
Self::UnexpectedTrailingCharacters => bug!("variant should not be used"),
Self::UnexpectedTrailingCharacters { never } => match *never {},
}
}
}
Expand All @@ -40,7 +43,7 @@ impl std::error::Error for Parse {
Self::TryFromParsed(err) => Some(err),
Self::ParseFromDescription(err) => Some(err),
#[allow(deprecated)]
Self::UnexpectedTrailingCharacters => bug!("variant should not be used"),
Self::UnexpectedTrailingCharacters { never } => match *never {},
}
}
}
Expand Down Expand Up @@ -85,7 +88,7 @@ impl From<Parse> for crate::Error {
Parse::TryFromParsed(err) => Self::TryFromParsed(err),
Parse::ParseFromDescription(err) => Self::ParseFromDescription(err),
#[allow(deprecated)]
Parse::UnexpectedTrailingCharacters => bug!("variant should not be used"),
Parse::UnexpectedTrailingCharacters { never } => match never {},
}
}
}
Expand All @@ -97,7 +100,7 @@ impl TryFrom<crate::Error> for Parse {
match err {
crate::Error::ParseFromDescription(err) => Ok(Self::ParseFromDescription(err)),
#[allow(deprecated)]
crate::Error::UnexpectedTrailingCharacters => bug!("variant should not be used"),
crate::Error::UnexpectedTrailingCharacters { never } => match never {},
crate::Error::TryFromParsed(err) => Ok(Self::TryFromParsed(err)),
_ => Err(error::DifferentVariant),
}
Expand Down

0 comments on commit dad76cb

Please sign in to comment.