aboutsummaryrefslogtreecommitdiff
path: root/src/parse_trait_sig.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse_trait_sig.rs')
-rw-r--r--src/parse_trait_sig.rs34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/parse_trait_sig.rs b/src/parse_trait_sig.rs
index aff4fe9..dfe3ce7 100644
--- a/src/parse_trait_sig.rs
+++ b/src/parse_trait_sig.rs
@@ -28,13 +28,17 @@ pub enum MethodError {
AssocTypeInInputs,
ImplTraitInInputs,
- // TODO: wrap TransformError
- AssocTypeWithoutDestType,
- UnsupportedType,
+ Transform(TransformError),
UnconvertedAssocType,
}
+impl From<TransformError> for MethodError {
+ fn from(err: TransformError) -> Self {
+ Self::Transform(err)
+ }
+}
+
fn filter_map_impl_trait(item: TypeOrPath) -> Option<&TypeImplTrait> {
match item {
TypeOrPath::Type(Type::ImplTrait(impltrait)) => Some(impltrait),
@@ -72,11 +76,8 @@ pub fn parse_trait_signature(
let return_type = match &mut signature.output {
ReturnType::Type(_, og_type) => match type_converter.convert_type(og_type) {
Ok(ret_type) => ret_type,
- Err((span, TransformError::AssocTypeWithoutDestType)) => {
- return Err((span, MethodError::AssocTypeWithoutDestType));
- }
- Err((span, TransformError::UnsupportedType)) => {
- return Err((span, MethodError::UnsupportedType));
+ Err((span, err)) => {
+ return Err((span, err.into()));
}
},
ReturnType::Default => TypeTransform::NoOp,
@@ -144,7 +145,7 @@ mod tests {
use crate::{
parse_assoc_type::DestType,
parse_trait_sig::{parse_trait_signature, MethodError, SignatureChanges, TypeTransform},
- transform::TypeConverter,
+ transform::{TransformError, TypeConverter},
};
#[test]
@@ -194,7 +195,10 @@ mod tests {
assert!(matches!(
parse_trait_signature(&mut type1.sig, &Default::default()),
- Err((_, MethodError::AssocTypeWithoutDestType))
+ Err((
+ _,
+ MethodError::Transform(TransformError::AssocTypeWithoutDestType)
+ ))
));
}
@@ -259,7 +263,7 @@ mod tests {
assert!(matches!(
parse_trait_signature(&mut type1.sig, &Default::default()),
- Err((_, MethodError::UnsupportedType))
+ Err((_, MethodError::Transform(TransformError::UnsupportedType)))
));
}
@@ -272,7 +276,7 @@ mod tests {
assert!(matches!(
parse_trait_signature(&mut type1.sig, &Default::default()),
- Err((_, MethodError::UnsupportedType))
+ Err((_, MethodError::Transform(TransformError::UnsupportedType)))
));
}
@@ -285,7 +289,7 @@ mod tests {
assert!(matches!(
parse_trait_signature(&mut type1.sig, &Default::default()),
- Err((_, MethodError::UnsupportedType))
+ Err((_, MethodError::Transform(TransformError::UnsupportedType)))
));
}
@@ -298,7 +302,7 @@ mod tests {
assert!(matches!(
parse_trait_signature(&mut type1.sig, &Default::default()),
- Err((_, MethodError::UnsupportedType))
+ Err((_, MethodError::Transform(TransformError::UnsupportedType)))
));
}
@@ -350,7 +354,7 @@ mod tests {
assert!(matches!(
parse_trait_signature(&mut type1.sig, &Default::default()),
- Err((_, MethodError::UnsupportedType))
+ Err((_, MethodError::Transform(TransformError::UnsupportedType)))
));
}
}