Skip to content

Commit

Permalink
Refactor: remove check_custom_impl by inlining into check_custom (#604)
Browse files Browse the repository at this point in the history
`check_custom_impl` had only one callsite.
  • Loading branch information
acl-cqc authored Oct 13, 2023
1 parent f394ad4 commit 9f7ebfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
25 changes: 0 additions & 25 deletions src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,6 @@ trait TypeParametrised {
}
Ok(())
}

/// Check custom instance is a valid instantiation of this definition.
///
/// # Errors
///
/// This function will return an error if the type of the instance does not
/// match the definition.
fn check_concrete_impl(&self, custom: &Self::Concrete) -> Result<(), SignatureError> {
if self.extension() != custom.parent_extension() {
return Err(SignatureError::ExtensionMismatch(
self.extension().clone(),
custom.parent_extension().clone(),
));
}
if self.name() != custom.def_name() {
return Err(SignatureError::NameMismatch(
self.name().clone(),
custom.def_name().clone(),
));
}

self.check_args_impl(custom.type_args())?;

Ok(())
}
}

/// A constant value provided by a extension.
Expand Down
18 changes: 16 additions & 2 deletions src/extension/type_def.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::hash_map::Entry;

use super::ExtensionBuildError;
use super::{CustomConcrete, ExtensionBuildError};
use super::{Extension, ExtensionId, SignatureError, TypeParametrised};

use crate::types::{least_upper_bound, CustomType};
Expand Down Expand Up @@ -61,7 +61,21 @@ impl TypeDef {
/// This function will return an error if the type of the instance does not
/// match the definition.
pub fn check_custom(&self, custom: &CustomType) -> Result<(), SignatureError> {
self.check_concrete_impl(custom)?;
if self.extension() != custom.parent_extension() {
return Err(SignatureError::ExtensionMismatch(
self.extension().clone(),
custom.parent_extension().clone(),
));
}
if self.name() != custom.def_name() {
return Err(SignatureError::NameMismatch(
self.name().clone(),
custom.def_name().clone(),
));
}

self.check_args_impl(custom.type_args())?;

let calc_bound = self.bound(custom.args());
if calc_bound == custom.bound() {
Ok(())
Expand Down

0 comments on commit 9f7ebfd

Please sign in to comment.