fix: Stop using `displaydoc` (#8614)

* Stop using `displaydoc`

* Fix comment alignment

This commit is unrelated to the solution in this branch. There's a new
lint that produces a warning when lists in comments are not aligned well.
This commit is contained in:
Marek 2024-06-17 17:10:41 +02:00 committed by GitHub
parent 8f27d972fa
commit c6f575319d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 80 additions and 32 deletions

View File

@ -1251,17 +1251,6 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "displaydoc"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.66",
]
[[package]]
name = "document-features"
version = "0.2.8"
@ -6012,7 +6001,6 @@ dependencies = [
"chrono",
"color-eyre",
"criterion",
"displaydoc",
"ed25519-zebra",
"equihash",
"futures",
@ -6070,7 +6058,6 @@ dependencies = [
"bls12_381",
"chrono",
"color-eyre",
"displaydoc",
"futures",
"futures-util",
"halo2_proofs",
@ -6255,7 +6242,6 @@ dependencies = [
name = "zebra-script"
version = "1.0.0-beta.37"
dependencies = [
"displaydoc",
"hex",
"lazy_static",
"thiserror",

View File

@ -107,7 +107,6 @@ chrono = { version = "0.4.38", default-features = false, features = ["clock", "s
humantime = "2.1.0"
# Error Handling & Formatting
displaydoc = "0.2.4"
static_assertions = "1.1.0"
thiserror = "1.0.61"
tracing = "0.1.39"

View File

@ -429,8 +429,8 @@ where
}
}
#[derive(thiserror::Error, Debug, displaydoc::Display, Clone, PartialEq, Eq)]
#[allow(missing_docs)]
#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
/// Errors that can be returned when validating `Amount`s
pub enum Error {
/// input {value} is outside of valid range for zatoshi Amount, valid_range={range:?}
@ -462,6 +462,34 @@ pub enum Error {
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&match self {
Error::Constraint { value, range } => format!(
"input {value} is outside of valid range for zatoshi Amount, valid_range={range:?}"
),
Error::Convert { value, .. } => {
format!("{value} could not be converted to an i64 Amount")
}
Error::MultiplicationOverflow {
amount,
multiplier,
overflowing_result,
} => format!(
"overflow when calculating {amount}i64 * {multiplier}u64 = {overflowing_result}i128"
),
Error::DivideByZero { amount } => format!("cannot divide amount {amount} by zero"),
Error::SumOverflow {
partial_sum,
remaining_items,
} => format!(
"overflow when summing i64 amounts; \
partial sum: {partial_sum}, number of remaining items: {remaining_items}"
),
})
}
}
impl Error {
/// Returns the invalid value for this error.
///

View File

@ -6,6 +6,7 @@ use crate::{
transparent,
};
use core::fmt;
use std::{borrow::Borrow, collections::HashMap};
#[cfg(any(test, feature = "proptest-impl"))]
@ -385,7 +386,7 @@ impl ValueBalance<NonNegative> {
}
}
#[derive(thiserror::Error, Debug, displaydoc::Display, Clone, PartialEq, Eq)]
#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
/// Errors that can be returned when validating a [`ValueBalance`]
pub enum ValueBalanceError {
/// transparent amount error {0}
@ -401,6 +402,17 @@ pub enum ValueBalanceError {
Orchard(amount::Error),
}
impl fmt::Display for ValueBalanceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&match self {
Transparent(e) => format!("transparent amount err: {e}"),
Sprout(e) => format!("sprout amount err: {e}"),
Sapling(e) => format!("sapling amount err: {e}"),
Orchard(e) => format!("orchard amount err: {e}"),
})
}
}
impl<C> std::ops::Add for ValueBalance<C>
where
C: Constraint,

View File

@ -44,7 +44,6 @@ rand = "0.8.5"
rayon = "1.10.0"
chrono = { version = "0.4.38", default-features = false, features = ["clock", "std"] }
displaydoc = "0.2.4"
lazy_static = "1.4.0"
once_cell = "1.18.0"
serde = { version = "1.0.203", features = ["serde_derive"] }

View File

@ -12,13 +12,13 @@
//! Otherwise, verification of out-of-order and invalid blocks and transactions can hang
//! indefinitely.
use core::fmt;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
use displaydoc::Display;
use futures::{FutureExt, TryFutureExt};
use thiserror::Error;
use tokio::task::JoinHandle;
@ -91,7 +91,7 @@ where
/// An error while semantically verifying a block.
//
// One or both of these error variants are at least 140 bytes
#[derive(Debug, Display, Error)]
#[derive(Debug, Error)]
#[allow(missing_docs)]
pub enum RouterError {
/// Block could not be checkpointed
@ -100,6 +100,19 @@ pub enum RouterError {
Block { source: Box<VerifyBlockError> },
}
impl fmt::Display for RouterError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&match self {
RouterError::Checkpoint { source } => {
format!("block could not be checkpointed due to: {source}")
}
RouterError::Block { source } => {
format!("block could not be full-verified due to: {source}")
}
})
}
}
impl From<VerifyCheckpointError> for RouterError {
fn from(err: VerifyCheckpointError) -> Self {
RouterError::Checkpoint {

View File

@ -20,7 +20,6 @@ zcash_script = "0.1.15"
zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.37" }
thiserror = "1.0.61"
displaydoc = "0.2.4"
[dev-dependencies]
hex = "0.4.3"

View File

@ -5,9 +5,9 @@
// We allow unsafe code, so we can call zcash_script
#![allow(unsafe_code)]
use core::fmt;
use std::sync::Arc;
use displaydoc::Display;
use thiserror::Error;
use zcash_script::{
@ -22,27 +22,39 @@ use zebra_chain::{
transparent,
};
#[derive(Copy, Clone, Debug, Display, Error, PartialEq, Eq)]
#[non_exhaustive]
/// An Error type representing the error codes returned from zcash_script.
#[derive(Copy, Clone, Debug, Error, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// script failed to verify
/// script verification failed
#[non_exhaustive]
ScriptInvalid,
/// could not to deserialize tx
/// could not deserialize tx
#[non_exhaustive]
TxDeserialize,
/// input index out of bounds for transaction's inputs
/// input index out of bounds
#[non_exhaustive]
TxIndex,
/// tx is an invalid size for it's protocol
/// tx has an invalid size
#[non_exhaustive]
TxSizeMismatch,
/// encountered unknown error kind from zcash_script: {0}
/// unknown error from zcash_script: {0}
#[non_exhaustive]
Unknown(zcash_script_error_t),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&match self {
Error::ScriptInvalid => "script verification failed".to_owned(),
Error::TxDeserialize => "could not deserialize tx".to_owned(),
Error::TxIndex => "input index out of bounds".to_owned(),
Error::TxSizeMismatch => "tx has an invalid size".to_owned(),
Error::Unknown(e) => format!("unknown error from zcash_script: {e}"),
})
}
}
impl From<zcash_script_error_t> for Error {
#[allow(non_upper_case_globals)]
fn from(err_code: zcash_script_error_t) -> Error {

View File

@ -168,9 +168,9 @@ impl Argument {
///
/// # Implementation
///
/// 1. Generate a list with less than ten random strings. Then proceed by selecting which strings
/// will become key value pairs, and generate a new random string for each value that needs to
/// be paired to an argument key.
/// 1. Generate a list with less than ten random strings. Then proceed by selecting which
/// strings will become key value pairs, and generate a new random string for each value that
/// needs to be paired to an argument key.
pub fn list_strategy() -> impl Strategy<Value = Vec<Argument>> {
// Generate a list with less than ten unique random strings.
hash_set("\\PC+", 0..10)