diff --git a/src/extension.rs b/src/extension.rs index 1fab017e2..aec4f6020 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -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. diff --git a/src/extension/type_def.rs b/src/extension/type_def.rs index abc88e823..1ad0d28ac 100644 --- a/src/extension/type_def.rs +++ b/src/extension/type_def.rs @@ -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}; @@ -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(())