From c900129f2c4a4b5f839b6d1260aeddc5ef2a0ed3 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Sat, 5 Nov 2022 13:21:12 +0100 Subject: [PATCH 1/2] Change to non_exhaustive attributes --- src/error.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/error.rs b/src/error.rs index 5653d00..3a4aeae 100644 --- a/src/error.rs +++ b/src/error.rs @@ -43,6 +43,7 @@ pub enum TiffError { /// The list of variants may grow to incorporate errors of future features. Matching against this /// exhaustively is not covered by interface stability guarantees. #[derive(Debug, Clone, PartialEq)] +#[non_exhaustive] pub enum TiffFormatError { TiffSignatureNotFound, TiffSignatureInvalid, @@ -68,9 +69,6 @@ pub enum TiffFormatError { RequiredTagEmpty(Tag), StripTileTagConflict, CycleInOffsets, - #[doc(hidden)] - /// Do not match against this variant. It may get removed. - __NonExhaustive, } impl fmt::Display for TiffFormatError { @@ -121,7 +119,6 @@ impl fmt::Display for TiffFormatError { 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."), 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 /// stability guarantees. #[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[non_exhaustive] pub enum TiffUnsupportedError { FloatingPointPredictor(ColorType), HorizontalPredictor(ColorType), @@ -148,9 +146,6 @@ pub enum TiffUnsupportedError { UnsupportedBitsPerChannel(u8), UnsupportedPlanarConfig(Option), UnsupportedDataType, - #[doc(hidden)] - /// Do not match against this variant. It may get removed. - __NonExhaustive, } impl fmt::Display for TiffUnsupportedError { @@ -196,7 +191,6 @@ impl fmt::Display for TiffUnsupportedError { write!(fmt, "Unsupported planar configuration “{:?}”.", config) } UnsupportedDataType => write!(fmt, "Unsupported data type."), - __NonExhaustive => unreachable!(), } } } From 0e9f8e3b5b3506ac64403b1e894af87dcb95481e Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Sat, 5 Nov 2022 13:25:20 +0100 Subject: [PATCH 2/2] Mark more tag enums as non_exhaustive --- src/decoder/ifd.rs | 8 +------- src/decoder/image.rs | 1 - src/decoder/mod.rs | 1 - src/tags.rs | 5 +---- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/decoder/ifd.rs b/src/decoder/ifd.rs index d028ebb..b05513d 100644 --- a/src/decoder/ifd.rs +++ b/src/decoder/ifd.rs @@ -17,6 +17,7 @@ use self::Value::{ #[allow(unused_qualifications)] #[derive(Debug, Clone, PartialEq)] +#[non_exhaustive] pub enum Value { Byte(u8), Short(u16), @@ -34,8 +35,6 @@ pub enum Value { Ascii(String), Ifd(u32), IfdBig(u64), - #[doc(hidden)] // Do not match against this. - __NonExhaustive, } impl Value { @@ -361,7 +360,6 @@ impl Entry { | Type::RATIONAL | Type::SRATIONAL | Type::IFD8 => 8, - Type::__NonExhaustive => unreachable!(), }; let value_bytes = match self.count.checked_mul(tag_size) { @@ -398,7 +396,6 @@ impl Entry { | Type::SLONG | Type::FLOAT | Type::IFD => unreachable!(), - Type::__NonExhaustive => unreachable!(), }); } @@ -444,7 +441,6 @@ impl Entry { reader.goto_offset(self.r(bo).read_u32()?.into())?; IfdBig(reader.read_u64()?) } - Type::__NonExhaustive => unreachable!(), }); } @@ -528,7 +524,6 @@ impl Entry { | Type::IFD8 => { unreachable!() } - Type::__NonExhaustive => unreachable!(), } } @@ -611,7 +606,6 @@ impl Entry { } Ok(Ascii(String::from_utf8(out)?)) } - Type::__NonExhaustive => unreachable!(), } } diff --git a/src/decoder/image.rs b/src/decoder/image.rs index 5106a88..c5c884f 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -464,7 +464,6 @@ impl Image { TiffUnsupportedError::FloatingPointPredictor(color_type), )); } - Predictor::__NonExhaustive => unreachable!(), }, (type_, _) => { return Err(TiffError::UnsupportedError( diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index d3fa2da..5fa1812 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -429,7 +429,6 @@ fn fix_endianness_and_predict( _ => unreachable!("Caller should have validated arguments. Please file a bug."), } } - Predictor::__NonExhaustive => unreachable!(), } } diff --git a/src/tags.rs b/src/tags.rs index 04cb5ec..cbf7472 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -9,11 +9,9 @@ macro_rules! tags { } => { $( #[$enum_attr] )* #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] + #[non_exhaustive] pub enum $name { $($(#[$ident_attr])* $tag,)* - // FIXME: switch to non_exhaustive once stabilized and compiler requirement new enough - #[doc(hidden)] - __NonExhaustive, $( #[doc = $unknown_doc] Unknown($ty), @@ -34,7 +32,6 @@ macro_rules! tags { match *self { $( $name::$tag => $val, )* $( $name::Unknown(n) => { $unknown_doc; n }, )* - $name::__NonExhaustive => unreachable!(), } } }