Skip to content

Commit

Permalink
workaround a derive_more linting error
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Oct 21, 2024
1 parent 931448a commit 65acbb2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
36 changes: 33 additions & 3 deletions hugr-core/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,29 +275,59 @@ pub enum PackageEncodingError {
}

/// Error raised while validating a package.
#[derive(Debug, Display, Error, From)]
#[derive(Debug, From)]
#[non_exhaustive]
pub enum PackageValidationError {
/// Error raised while processing the package extensions.
Extension(ExtensionRegistryError),
/// Error raised while validating the package hugrs.
Validation(ValidationError),
/// Error validating HUGR.
// TODO: Remove manual Display and Error impls when removing deprecated variants.
#[from(ignore)]
#[deprecated(
since = "0.13.2",
note = "Replaced by `PackageValidationError::Validation`"
)]
#[from(ignore)]
Validate(ValidationError),
/// Error registering extension.
// TODO: Remove manual Display and Error impls when removing deprecated variants.
#[from(ignore)]
#[deprecated(
since = "0.13.2",
note = "Replaced by `PackageValidationError::Extension`"
)]
#[from(ignore)]
ExtReg(ExtensionRegistryError),
}

// Note: We cannot use the `derive_more::Error` derive due to a bug with deprecated elements.
// See https://github.com/JelteF/derive_more/issues/419
#[allow(deprecated)]
impl std::error::Error for PackageValidationError {
fn source(&self) -> Option<&(dyn derive_more::Error + 'static)> {
match self {
PackageValidationError::Extension(source) => Some(source),
PackageValidationError::Validation(source) => Some(source),
PackageValidationError::Validate(source) => Some(source),
PackageValidationError::ExtReg(source) => Some(source),
}
}
}

// Note: We cannot use the `derive_more::Display` derive due to a bug with deprecated elements.
// See https://github.com/JelteF/derive_more/issues/419
impl Display for PackageValidationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
#[allow(deprecated)]
match self {
PackageValidationError::Extension(e) => write!(f, "Error processing extensions: {}", e),
PackageValidationError::Validation(e) => write!(f, "Error validating HUGR: {}", e),
PackageValidationError::Validate(e) => write!(f, "Error validating HUGR: {}", e),
PackageValidationError::ExtReg(e) => write!(f, "Error registering extension: {}", e),
}
}
}

#[cfg(test)]
mod test {
use cool_asserts::assert_matches;
Expand Down
2 changes: 1 addition & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"hidden": true
}
]
}
}

0 comments on commit 65acbb2

Please sign in to comment.