aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-22 12:22:22 +0100
committerMartin Fischer <martin@push-f.com>2021-11-22 12:23:16 +0100
commit890247746e74e015acbb290c925284c5047a580c (patch)
tree1b8820f5afc5d4ef200d1b774112f385e32188b0
parente8581b5034c52636f4f76a8e91b57e7752323d04 (diff)
refactor: use nested match blocks
-rw-r--r--src/lib.rs62
1 files changed, 32 insertions, 30 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 02b150e..67c1223 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -72,6 +72,11 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream {
for item in &original_trait.items {
if let TraitItem::Type(assoc_type) = item {
match parse_assoc_type(assoc_type) {
+ Ok((ident, type_)) => {
+ type_converter
+ .assoc_type_conversions
+ .insert(ident.clone(), type_);
+ }
Err((_, AssocTypeError::NoTraitBound)) => continue,
Err((span, AssocTypeError::TraitBoundContainsAssocType)) => {
return abort!(span, "dynamize does not support associated types here")
@@ -82,11 +87,6 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream {
"dynamize does not (yet?) support generic associated types"
)
}
- Ok((ident, type_)) => {
- type_converter
- .assoc_type_conversions
- .insert(ident.clone(), type_);
- }
}
}
}
@@ -95,32 +95,34 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream {
if let TraitItem::Method(method) = item {
let mut signature = method.sig.clone();
match parse_trait_signature(&mut signature, &type_converter) {
- Err((_, MethodError::NonDispatchableMethod)) => continue,
- Err((span, MethodError::Transform(TransformError::AssocTypeWithoutDestType))) => {
- return abort!(
- span,
- "associated type is either undefined or doesn't have a trait bound"
- )
- }
- Err((span, MethodError::AssocTypeInInputs)) => {
- return abort!(
- span,
- "dynamize does not support associated types in parameter types"
- )
- }
- Err((span, MethodError::Transform(TransformError::UnsupportedType))) => {
- return abort!(span, "dynamize does not know how to convert this type")
- }
- Err((span, MethodError::UnconvertedAssocType)) => {
- return abort!(span, "dynamize does not support associated types here")
- }
- Err((span, MethodError::ImplTraitInInputs)) => {
- return abort!(
- span,
- "dynamize does not support impl here, change it to a method generic"
- )
- }
Ok(parsed_method) => objectifiable_methods.push((signature, parsed_method)),
+ Err((span, err)) => match err {
+ MethodError::NonDispatchableMethod => continue,
+ MethodError::AssocTypeInInputs => {
+ return abort!(
+ span,
+ "dynamize does not support associated types in parameter types"
+ )
+ }
+ MethodError::ImplTraitInInputs => {
+ return abort!(
+ span,
+ "dynamize does not support impl here, change it to a method generic"
+ )
+ }
+ MethodError::Transform(TransformError::AssocTypeWithoutDestType) => {
+ return abort!(
+ span,
+ "associated type is either undefined or doesn't have a trait bound"
+ )
+ }
+ MethodError::Transform(TransformError::UnsupportedType) => {
+ return abort!(span, "dynamize does not know how to convert this type")
+ }
+ MethodError::UnconvertedAssocType => {
+ return abort!(span, "dynamize does not support associated types here")
+ }
+ },
};
}
}