aboutsummaryrefslogtreecommitdiff
path: root/src/parse_trait_sig.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-20 15:10:23 +0100
committerMartin Fischer <martin@push-f.com>2021-11-20 18:36:07 +0100
commit91ca29ade1ab6b90dda972c2a42a5dc529ddfb44 (patch)
treeaec288a5858fe3e8a90f0357c69571e091cf85d6 /src/parse_trait_sig.rs
parente918eb0ab2cf6d84751f5f52b49414d382b7abbb (diff)
refactor: traverse AST via iterators
Diffstat (limited to 'src/parse_trait_sig.rs')
-rw-r--r--src/parse_trait_sig.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/parse_trait_sig.rs b/src/parse_trait_sig.rs
index 76402ac..508e131 100644
--- a/src/parse_trait_sig.rs
+++ b/src/parse_trait_sig.rs
@@ -6,10 +6,10 @@ use syn::{
};
use syn::{Ident, Signature, TypeImplTrait};
+use crate::match_assoc_type;
use crate::parse_assoc_type::BoxType;
-use crate::syn_utils::{find_in_type, trait_bounds, TypeMatcher};
+use crate::syn_utils::{iter_type, trait_bounds, TypeOrPath};
use crate::transform::{dynamize_function_bounds, AssocTypeConversions, TransformError};
-use crate::AssocTypeMatcher;
#[derive(Debug, Clone)]
pub enum TypeTransform {
@@ -31,14 +31,10 @@ pub enum MethodParseError {
UnconvertibleAssocType,
}
-struct ImplTraitMatcher;
-impl TypeMatcher<TypeImplTrait> for ImplTraitMatcher {
- fn match_type<'a>(&self, t: &'a Type) -> Option<&'a TypeImplTrait> {
- if let Type::ImplTrait(impltrait) = t {
- Some(impltrait)
- } else {
- None
- }
+fn filter_map_impl_trait(item: TypeOrPath) -> Option<&TypeImplTrait> {
+ match item {
+ TypeOrPath::Type(Type::ImplTrait(impltrait)) => Some(impltrait),
+ _other => None,
}
}
@@ -58,10 +54,10 @@ pub fn parse_trait_signature(
// provide better error messages for associated types in params
for input in &signature.inputs {
if let FnArg::Typed(pattype) = input {
- if find_in_type(&pattype.ty, &AssocTypeMatcher).is_some() {
+ if iter_type(&pattype.ty).any(match_assoc_type) {
return Err((pattype.ty.span(), MethodParseError::AssocTypeInInputs));
}
- if let Some(impl_trait) = find_in_type(&pattype.ty, &ImplTraitMatcher) {
+ if let Some(impl_trait) = iter_type(&pattype.ty).find_map(filter_map_impl_trait) {
return Err((impl_trait.span(), MethodParseError::ImplTraitInInputs));
}
}