Merge pull request #189 from image-rs/non-exhaustive-enumeration

Non exhaustive enumerations
This commit is contained in:
HeroicKatora authored and GitHub committed 2022-11-10 17:27:31 +01:00
commit 7679be19c1
5 files changed
+4 -21

No files matched your search

+1 -7
View File
@@ -17,6 +17,7 @@ use self::Value::{
#[allow(unused_qualifications)] #[allow(unused_qualifications)]
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum Value { pub enum Value {
Byte(u8), Byte(u8),
Short(u16), Short(u16),
@@ -34,8 +35,6 @@ pub enum Value {
Ascii(String), Ascii(String),
Ifd(u32), Ifd(u32),
IfdBig(u64), IfdBig(u64),
#[doc(hidden)] // Do not match against this.
__NonExhaustive,
} }
impl Value { impl Value {
@@ -361,7 +360,6 @@ impl Entry {
| Type::RATIONAL | Type::RATIONAL
| Type::SRATIONAL | Type::SRATIONAL
| Type::IFD8 => 8, | Type::IFD8 => 8,
Type::__NonExhaustive => unreachable!(),
}; };
let value_bytes = match self.count.checked_mul(tag_size) { let value_bytes = match self.count.checked_mul(tag_size) {
@@ -398,7 +396,6 @@ impl Entry {
| Type::SLONG | Type::SLONG
| Type::FLOAT | Type::FLOAT
| Type::IFD => unreachable!(), | Type::IFD => unreachable!(),
Type::__NonExhaustive => unreachable!(),
}); });
} }
@@ -444,7 +441,6 @@ impl Entry {
reader.goto_offset(self.r(bo).read_u32()?.into())?; reader.goto_offset(self.r(bo).read_u32()?.into())?;
IfdBig(reader.read_u64()?) IfdBig(reader.read_u64()?)
} }
Type::__NonExhaustive => unreachable!(),
}); });
} }
@@ -528,7 +524,6 @@ impl Entry {
| Type::IFD8 => { | Type::IFD8 => {
unreachable!() unreachable!()
} }
Type::__NonExhaustive => unreachable!(),
} }
} }
@@ -611,7 +606,6 @@ impl Entry {
} }
Ok(Ascii(String::from_utf8(out)?)) Ok(Ascii(String::from_utf8(out)?))
} }
Type::__NonExhaustive => unreachable!(),
} }
} }
-1
View File
@@ -464,7 +464,6 @@ impl Image {
TiffUnsupportedError::FloatingPointPredictor(color_type), TiffUnsupportedError::FloatingPointPredictor(color_type),
)); ));
} }
Predictor::__NonExhaustive => unreachable!(),
}, },
(type_, _) => { (type_, _) => {
return Err(TiffError::UnsupportedError( return Err(TiffError::UnsupportedError(
-1
View File
@@ -429,7 +429,6 @@ fn fix_endianness_and_predict(
_ => unreachable!("Caller should have validated arguments. Please file a bug."), _ => unreachable!("Caller should have validated arguments. Please file a bug."),
} }
} }
Predictor::__NonExhaustive => unreachable!(),
} }
} }
+2 -8
View File
@@ -43,6 +43,7 @@ pub enum TiffError {
/// The list of variants may grow to incorporate errors of future features. Matching against this /// The list of variants may grow to incorporate errors of future features. Matching against this
/// exhaustively is not covered by interface stability guarantees. /// exhaustively is not covered by interface stability guarantees.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum TiffFormatError { pub enum TiffFormatError {
TiffSignatureNotFound, TiffSignatureNotFound,
TiffSignatureInvalid, TiffSignatureInvalid,
@@ -68,9 +69,6 @@ pub enum TiffFormatError {
RequiredTagEmpty(Tag), RequiredTagEmpty(Tag),
StripTileTagConflict, StripTileTagConflict,
CycleInOffsets, CycleInOffsets,
#[doc(hidden)]
/// Do not match against this variant. It may get removed.
__NonExhaustive,
} }
impl fmt::Display for TiffFormatError { impl fmt::Display for TiffFormatError {
@@ -121,7 +119,6 @@ impl fmt::Display for TiffFormatError {
RequiredTagEmpty(ref val) => write!(fmt, "Required tag {:?} was empty.", val), RequiredTagEmpty(ref val) => write!(fmt, "Required tag {:?} was empty.", val),
StripTileTagConflict => write!(fmt, "File should contain either (StripByteCounts and StripOffsets) or (TileByteCounts and TileOffsets), other combination was found."), StripTileTagConflict => write!(fmt, "File should contain either (StripByteCounts and StripOffsets) or (TileByteCounts and TileOffsets), other combination was found."),
CycleInOffsets => write!(fmt, "File contained a cycle in the list of IFDs"), CycleInOffsets => write!(fmt, "File contained a cycle in the list of IFDs"),
__NonExhaustive => unreachable!(),
} }
} }
} }
@@ -135,6 +132,7 @@ impl fmt::Display for TiffFormatError {
/// The list of variants may grow. Matching against this exhaustively is not covered by interface /// The list of variants may grow. Matching against this exhaustively is not covered by interface
/// stability guarantees. /// stability guarantees.
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TiffUnsupportedError { pub enum TiffUnsupportedError {
FloatingPointPredictor(ColorType), FloatingPointPredictor(ColorType),
HorizontalPredictor(ColorType), HorizontalPredictor(ColorType),
@@ -148,9 +146,6 @@ pub enum TiffUnsupportedError {
UnsupportedBitsPerChannel(u8), UnsupportedBitsPerChannel(u8),
UnsupportedPlanarConfig(Option<PlanarConfiguration>), UnsupportedPlanarConfig(Option<PlanarConfiguration>),
UnsupportedDataType, UnsupportedDataType,
#[doc(hidden)]
/// Do not match against this variant. It may get removed.
__NonExhaustive,
} }
impl fmt::Display for TiffUnsupportedError { impl fmt::Display for TiffUnsupportedError {
@@ -196,7 +191,6 @@ impl fmt::Display for TiffUnsupportedError {
write!(fmt, "Unsupported planar configuration “{:?}”.", config) write!(fmt, "Unsupported planar configuration “{:?}”.", config)
} }
UnsupportedDataType => write!(fmt, "Unsupported data type."), UnsupportedDataType => write!(fmt, "Unsupported data type."),
__NonExhaustive => unreachable!(),
} }
} }
} }
+1 -4
View File
@@ -9,11 +9,9 @@ macro_rules! tags {
} => { } => {
$( #[$enum_attr] )* $( #[$enum_attr] )*
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
#[non_exhaustive]
pub enum $name { pub enum $name {
$($(#[$ident_attr])* $tag,)* $($(#[$ident_attr])* $tag,)*
// FIXME: switch to non_exhaustive once stabilized and compiler requirement new enough
#[doc(hidden)]
__NonExhaustive,
$( $(
#[doc = $unknown_doc] #[doc = $unknown_doc]
Unknown($ty), Unknown($ty),
@@ -34,7 +32,6 @@ macro_rules! tags {
match *self { match *self {
$( $name::$tag => $val, )* $( $name::$tag => $val, )*
$( $name::Unknown(n) => { $unknown_doc; n }, )* $( $name::Unknown(n) => { $unknown_doc; n }, )*
$name::__NonExhaustive => unreachable!(),
} }
} }
} }