Skip to content

Commit dcb8001

Browse files
committed
Remove Uninhabited
Last release, before we had access to `non_exhaustive` we added some fancy types to enable conditionally having a `bitcoinconsensus::Error`. Now that we have bumped the MSRV and have already added `non_exhaustive` to the `Error` type in question, we can use a compiler attribute to conditionally include the `bitcoinconsensus` error. Remove `Uninhabited` and its usage.
1 parent 6f89b71 commit dcb8001

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/blockdata/script.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,38 +161,22 @@ pub enum Error {
161161
/// Tried to read an array off the stack as a number when it was more than 4 bytes
162162
NumericOverflow,
163163
/// Error validating the script with bitcoinconsensus library
164-
BitcoinConsensus(BitcoinConsensusError),
164+
#[cfg(feature = "bitcoinconsensus")]
165+
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoinconsensus")))]
166+
BitcoinConsensus(bitcoinconsensus::Error),
165167
/// Can not find the spent output
166168
UnknownSpentOutput(OutPoint),
167169
/// Can not serialize the spending transaction
168170
SerializationError
169171
}
170172

171-
/// A [`bitcoinconsensus::Error`] alias. Exists to enable the compiler to ensure `bitcoinconsensus`
172-
/// feature gating is correct.
173-
#[cfg(feature = "bitcoinconsensus")]
174-
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoinconsensus")))]
175-
pub type BitcoinConsensusError = bitcoinconsensus::Error;
176-
177-
/// Dummy error type used when `bitcoinconsensus` feature is not enabled.
178-
#[cfg(not(feature = "bitcoinconsensus"))]
179-
#[cfg_attr(docsrs, doc(cfg(not(feature = "bitcoinconsensus"))))]
180-
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
181-
pub struct BitcoinConsensusError {
182-
_uninhabited: Uninhabited,
183-
}
184-
185-
#[cfg(not(feature = "bitcoinconsensus"))]
186-
#[cfg_attr(docsrs, doc(cfg(not(feature = "bitcoinconsensus"))))]
187-
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
188-
enum Uninhabited {}
189-
190173
impl fmt::Display for Error {
191174
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
192175
let str = match *self {
193176
Error::NonMinimalPush => "non-minimal datapush",
194177
Error::EarlyEndOfScript => "unexpected end of script",
195178
Error::NumericOverflow => "numeric overflow (number on stack larger than 4 bytes)",
179+
#[cfg(feature = "bitcoinconsensus")]
196180
Error::BitcoinConsensus(ref _n) => "bitcoinconsensus verification failed",
197181
Error::UnknownSpentOutput(ref _point) => "unknown spent output Transaction::verify()",
198182
Error::SerializationError => "can not serialize the spending transaction in Transaction::verify()",
@@ -211,9 +195,10 @@ impl std::error::Error for Error {
211195
NonMinimalPush
212196
| EarlyEndOfScript
213197
| NumericOverflow
214-
| BitcoinConsensus(_)
215198
| UnknownSpentOutput(_)
216199
| SerializationError => None,
200+
#[cfg(feature = "bitcoinconsensus")]
201+
BitcoinConsensus(_) => None,
217202
}
218203
}
219204
}

0 commit comments

Comments
 (0)