Merge rust-bitcoin/rust-bitcoin#1075: Remove Uninhabited
a8e62f249b
Remove Uninhabited (Tobin C. Harding) Pull request description: 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. For more context see the [original attempt ](https://github.com/rust-bitcoin/rust-bitcoin/pull/1025)at using `Infallible` (last comment in discussion thread). ACKs for top commit: Kixunil: ACKa8e62f249b
dunxen: ACKa8e62f2
apoelstra: ACKa8e62f249b
Tree-SHA512: 8c03c44d7533af1a9a1185b7f9e0fa2c52369eaac8a45f0e2199e7e1bbd08ba2bfa23d829d2c2abf7f45fe8cc26ccad02f2e1a6d408d2c0fbca23140cafe3801
This commit is contained in:
commit
05f7545aeb
|
@ -161,38 +161,22 @@ pub enum Error {
|
||||||
/// Tried to read an array off the stack as a number when it was more than 4 bytes
|
/// Tried to read an array off the stack as a number when it was more than 4 bytes
|
||||||
NumericOverflow,
|
NumericOverflow,
|
||||||
/// Error validating the script with bitcoinconsensus library
|
/// Error validating the script with bitcoinconsensus library
|
||||||
BitcoinConsensus(BitcoinConsensusError),
|
#[cfg(feature = "bitcoinconsensus")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoinconsensus")))]
|
||||||
|
BitcoinConsensus(bitcoinconsensus::Error),
|
||||||
/// Can not find the spent output
|
/// Can not find the spent output
|
||||||
UnknownSpentOutput(OutPoint),
|
UnknownSpentOutput(OutPoint),
|
||||||
/// Can not serialize the spending transaction
|
/// Can not serialize the spending transaction
|
||||||
SerializationError
|
SerializationError
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`bitcoinconsensus::Error`] alias. Exists to enable the compiler to ensure `bitcoinconsensus`
|
|
||||||
/// feature gating is correct.
|
|
||||||
#[cfg(feature = "bitcoinconsensus")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoinconsensus")))]
|
|
||||||
pub type BitcoinConsensusError = bitcoinconsensus::Error;
|
|
||||||
|
|
||||||
/// Dummy error type used when `bitcoinconsensus` feature is not enabled.
|
|
||||||
#[cfg(not(feature = "bitcoinconsensus"))]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(not(feature = "bitcoinconsensus"))))]
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
|
|
||||||
pub struct BitcoinConsensusError {
|
|
||||||
_uninhabited: Uninhabited,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "bitcoinconsensus"))]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(not(feature = "bitcoinconsensus"))))]
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
|
|
||||||
enum Uninhabited {}
|
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let str = match *self {
|
let str = match *self {
|
||||||
Error::NonMinimalPush => "non-minimal datapush",
|
Error::NonMinimalPush => "non-minimal datapush",
|
||||||
Error::EarlyEndOfScript => "unexpected end of script",
|
Error::EarlyEndOfScript => "unexpected end of script",
|
||||||
Error::NumericOverflow => "numeric overflow (number on stack larger than 4 bytes)",
|
Error::NumericOverflow => "numeric overflow (number on stack larger than 4 bytes)",
|
||||||
|
#[cfg(feature = "bitcoinconsensus")]
|
||||||
Error::BitcoinConsensus(ref _n) => "bitcoinconsensus verification failed",
|
Error::BitcoinConsensus(ref _n) => "bitcoinconsensus verification failed",
|
||||||
Error::UnknownSpentOutput(ref _point) => "unknown spent output Transaction::verify()",
|
Error::UnknownSpentOutput(ref _point) => "unknown spent output Transaction::verify()",
|
||||||
Error::SerializationError => "can not serialize the spending transaction in Transaction::verify()",
|
Error::SerializationError => "can not serialize the spending transaction in Transaction::verify()",
|
||||||
|
@ -211,9 +195,10 @@ impl std::error::Error for Error {
|
||||||
NonMinimalPush
|
NonMinimalPush
|
||||||
| EarlyEndOfScript
|
| EarlyEndOfScript
|
||||||
| NumericOverflow
|
| NumericOverflow
|
||||||
| BitcoinConsensus(_)
|
|
||||||
| UnknownSpentOutput(_)
|
| UnknownSpentOutput(_)
|
||||||
| SerializationError => None,
|
| SerializationError => None,
|
||||||
|
#[cfg(feature = "bitcoinconsensus")]
|
||||||
|
BitcoinConsensus(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue