aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-25 12:54:51 +0100
committerMartin Fischer <martin@push-f.com>2021-11-25 12:54:51 +0100
commitdc568083381d2073f0cfcfad8fa58158bd5bf811 (patch)
tree3c0655dd65c5912a4cbfd02bb4c9738e62074ccf /src
parent06a384000b0a6c7b657e4f8a9145b3d4357f3d70 (diff)
refactor: remove unnecessary TypeOrPath type
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs13
-rw-r--r--src/syn_utils.rs13
-rw-r--r--src/trait_sig.rs6
-rw-r--r--src/transform.rs2
4 files changed, 14 insertions, 20 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ace708c..1c7220f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -33,7 +33,6 @@ use syn::TypeParam;
use syn::TypeParamBound;
use syn::TypePath;
use syn::Visibility;
-use syn_utils::TypeOrPath;
use crate::parse_assoc_type::parse_assoc_type;
use crate::parse_assoc_type::AssocTypeError;
@@ -373,20 +372,20 @@ fn generate_blanket_impl(
}
}
-fn path_is_assoc_type(path: &Path) -> bool {
- path.segments[0].ident == "Self"
+fn path_is_assoc_type(path: &TypePath) -> bool {
+ path.path.segments[0].ident == "Self"
}
-fn match_assoc_type(item: TypeOrPath) -> bool {
- if let TypeOrPath::Path(path) = item {
+fn match_assoc_type(item: &Type) -> bool {
+ if let Type::Path(path) = item {
return path_is_assoc_type(path);
}
false
}
-fn filter_map_assoc_paths(item: TypeOrPath) -> Option<&Path> {
+fn filter_map_assoc_paths(item: &Type) -> Option<&TypePath> {
match item {
- TypeOrPath::Path(p) if path_is_assoc_type(p) => Some(p),
+ Type::Path(p) if path_is_assoc_type(p) => Some(p),
_other => None,
}
}
diff --git a/src/syn_utils.rs b/src/syn_utils.rs
index 00efee0..369aeb7 100644
--- a/src/syn_utils.rs
+++ b/src/syn_utils.rs
@@ -32,11 +32,6 @@ pub fn type_arguments_mut<P>(
})
}
-pub enum TypeOrPath<'a> {
- Type(&'a Type),
- Path(&'a Path),
-}
-
enum IterTypes<A, B, C, D, E, F> {
Single(A),
Function(B),
@@ -71,13 +66,13 @@ where
}
}
-pub fn iter_path(path: &Path) -> impl Iterator<Item = TypeOrPath> {
- iter::once(TypeOrPath::Path(path)).chain(types_in_path(path).flat_map(|t| iter_type(t)))
+pub fn iter_path(path: &Path) -> impl Iterator<Item = &Type> {
+ types_in_path(path).flat_map(|t| iter_type(t))
}
-pub fn iter_type<'a>(t: &'a Type) -> Box<dyn Iterator<Item = TypeOrPath<'a>> + 'a> {
+pub fn iter_type<'a>(t: &'a Type) -> Box<dyn Iterator<Item = &'a Type> + 'a> {
Box::new(
- iter::once(TypeOrPath::Type(t)).chain(match t {
+ iter::once(t).chain(match t {
Type::Array(array) => IterTypes::Single(iter_type(&array.elem)),
Type::Group(group) => IterTypes::Single(iter_type(&group.elem)),
Type::Paren(paren) => IterTypes::Single(iter_type(&paren.elem)),
diff --git a/src/trait_sig.rs b/src/trait_sig.rs
index 88aac6a..3fb439f 100644
--- a/src/trait_sig.rs
+++ b/src/trait_sig.rs
@@ -8,7 +8,7 @@ use syn::{Ident, Signature, TypeImplTrait};
use crate::match_assoc_type;
use crate::parse_assoc_type::BoxType;
-use crate::syn_utils::{iter_type, trait_bounds, TypeOrPath};
+use crate::syn_utils::{iter_type, trait_bounds};
use crate::transform::{dynamize_function_bounds, TransformError, TypeConverter};
#[derive(Debug, Clone)]
@@ -40,9 +40,9 @@ impl From<TransformError> for MethodError {
}
}
-fn filter_map_impl_trait(item: TypeOrPath) -> Option<&TypeImplTrait> {
+fn filter_map_impl_trait(item: &Type) -> Option<&TypeImplTrait> {
match item {
- TypeOrPath::Type(Type::ImplTrait(impltrait)) => Some(impltrait),
+ Type::ImplTrait(impltrait) => Some(impltrait),
_other => None,
}
}
diff --git a/src/transform.rs b/src/transform.rs
index 831fb14..39d3cab 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -64,7 +64,7 @@ impl TypeConverter<'_> {
..
}) = type_
{
- if let Type::Path(TypePath { qself: None, path }) = ty.as_ref() {
+ if let Type::Path(path) = ty.as_ref() {
if path_is_assoc_type(path) {
return Err((path.span(), TransformError::QualifiedSelfAssociatedType));
}