Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: remove check_custom_impl by inlining into check_custom #604

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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