diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-22 11:05:13 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-22 11:05:13 +0100 |
commit | 6b01f08fa1de6d67ab47ad19493ea683a75fc2ed (patch) | |
tree | 2edcd1e6cae887e7394dd95ea94666fbf62c0005 /src | |
parent | 8178b4671b03a9c7d4dbe6c4ce66b9cb737c4e2d (diff) |
rename MethodParseError to MethodError
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 18 | ||||
-rw-r--r-- | src/parse_trait_sig.rs | 44 | ||||
-rw-r--r-- | src/transform.rs | 19 |
3 files changed, 38 insertions, 43 deletions
@@ -39,7 +39,7 @@ use syn_utils::TypeOrPath; use crate::parse_assoc_type::parse_assoc_type; use crate::parse_assoc_type::AssocTypeError; use crate::parse_trait_sig::parse_trait_signature; -use crate::parse_trait_sig::MethodParseError; +use crate::parse_trait_sig::MethodError; use crate::parse_trait_sig::SignatureChanges; use crate::parse_trait_sig::TypeTransform; use crate::syn_utils::iter_path; @@ -94,14 +94,14 @@ 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((_, MethodParseError::NonDispatchableMethod)) => continue, - Err((span, MethodParseError::UnconvertibleAssocType)) => { + Err((_, MethodError::NonDispatchableMethod)) => continue, + Err((span, MethodError::UnconvertibleAssocType)) => { return abort!( span, "associated type is either undefined or doesn't have a trait bound" ) } - Err((span, MethodParseError::AssocTypeInInputs)) => { + Err((span, MethodError::AssocTypeInInputs)) => { return abort!( span, "dynamize does not support associated types in parameter types" @@ -109,15 +109,15 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { } Err(( span, - MethodParseError::AssocTypeInUnsupportedReturnType - | MethodParseError::UnconvertibleAssocTypeInFnInput, + MethodError::AssocTypeInUnsupportedReturnType + | MethodError::UnconvertibleAssocTypeInFnInput, )) => return abort!(span, "dynamize does not know how to convert this type"), Err(( span, - MethodParseError::UnconvertibleAssocTypeInTraitBound - | MethodParseError::UnconvertibleAssocTypeInWhereClause, + MethodError::UnconvertibleAssocTypeInTraitBound + | MethodError::UnconvertibleAssocTypeInWhereClause, )) => return abort!(span, "dynamize does not support associated types here"), - Err((span, MethodParseError::ImplTraitInInputs)) => { + Err((span, MethodError::ImplTraitInInputs)) => { return abort!( span, "dynamize does not support impl here, change it to a method generic" diff --git a/src/parse_trait_sig.rs b/src/parse_trait_sig.rs index 29b3205..9542a69 100644 --- a/src/parse_trait_sig.rs +++ b/src/parse_trait_sig.rs @@ -23,7 +23,7 @@ pub enum TypeTransform { } #[derive(Debug)] -pub enum MethodParseError { +pub enum MethodError { NonDispatchableMethod, AssocTypeInInputs, ImplTraitInInputs, @@ -49,19 +49,19 @@ pub struct SignatureChanges { pub fn parse_trait_signature( signature: &mut Signature, type_converter: &TypeConverter, -) -> Result<SignatureChanges, (Span, MethodParseError)> { +) -> Result<SignatureChanges, (Span, MethodError)> { if is_non_dispatchable(signature) { - return Err((signature.span(), MethodParseError::NonDispatchableMethod)); + return Err((signature.span(), MethodError::NonDispatchableMethod)); } // provide better error messages for associated types in params for input in &signature.inputs { if let FnArg::Typed(pattype) = input { if iter_type(&pattype.ty).any(match_assoc_type) { - return Err((pattype.ty.span(), MethodParseError::AssocTypeInInputs)); + return Err((pattype.ty.span(), MethodError::AssocTypeInInputs)); } if let Some(impl_trait) = iter_type(&pattype.ty).find_map(filter_map_impl_trait) { - return Err((impl_trait.span(), MethodParseError::ImplTraitInInputs)); + return Err((impl_trait.span(), MethodError::ImplTraitInInputs)); } } } @@ -72,10 +72,10 @@ pub fn parse_trait_signature( ReturnType::Type(_, og_type) => match type_converter.convert_type(og_type) { Ok(ret_type) => ret_type, Err(TransformError::UnconvertibleAssocType(span)) => { - return Err((span, MethodParseError::UnconvertibleAssocType)); + return Err((span, MethodError::UnconvertibleAssocType)); } Err(TransformError::AssocTypeInUnsupportedType(span)) => { - return Err((span, MethodParseError::AssocTypeInUnsupportedReturnType)); + return Err((span, MethodError::AssocTypeInUnsupportedReturnType)); } }, ReturnType::Default => TypeTransform::NoOp, @@ -142,9 +142,7 @@ mod tests { use crate::{ parse_assoc_type::DestType, - parse_trait_sig::{ - parse_trait_signature, MethodParseError, SignatureChanges, TypeTransform, - }, + parse_trait_sig::{parse_trait_signature, MethodError, SignatureChanges, TypeTransform}, transform::TypeConverter, }; @@ -195,7 +193,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::UnconvertibleAssocType)) + Err((_, MethodError::UnconvertibleAssocType)) )); } @@ -208,7 +206,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::NonDispatchableMethod)) + Err((_, MethodError::NonDispatchableMethod)) )); } @@ -221,7 +219,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::NonDispatchableMethod)) + Err((_, MethodError::NonDispatchableMethod)) )); } @@ -234,7 +232,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::NonDispatchableMethod)) + Err((_, MethodError::NonDispatchableMethod)) )); } @@ -247,7 +245,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::NonDispatchableMethod)) + Err((_, MethodError::NonDispatchableMethod)) )); } @@ -260,7 +258,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::AssocTypeInUnsupportedReturnType)) + Err((_, MethodError::AssocTypeInUnsupportedReturnType)) )); } @@ -273,7 +271,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::AssocTypeInUnsupportedReturnType)) + Err((_, MethodError::AssocTypeInUnsupportedReturnType)) )); } @@ -286,7 +284,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::AssocTypeInUnsupportedReturnType)) + Err((_, MethodError::AssocTypeInUnsupportedReturnType)) )); } @@ -299,7 +297,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::AssocTypeInUnsupportedReturnType)) + Err((_, MethodError::AssocTypeInUnsupportedReturnType)) )); } @@ -312,7 +310,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::AssocTypeInInputs)) + Err((_, MethodError::AssocTypeInInputs)) )); } @@ -325,7 +323,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::AssocTypeInInputs)) + Err((_, MethodError::AssocTypeInInputs)) )); } @@ -338,7 +336,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::ImplTraitInInputs)) + Err((_, MethodError::ImplTraitInInputs)) )); } @@ -351,7 +349,7 @@ mod tests { assert!(matches!( parse_trait_signature(&mut type1.sig, &Default::default()), - Err((_, MethodParseError::UnconvertibleAssocTypeInFnInput)) + Err((_, MethodError::UnconvertibleAssocTypeInFnInput)) )); } } diff --git a/src/transform.rs b/src/transform.rs index f2744cf..cf18456 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -10,7 +10,7 @@ use syn::{ use crate::{ filter_map_assoc_paths, match_assoc_type, parse_assoc_type::{BoxType, DestType}, - parse_trait_sig::{MethodParseError, TypeTransform}, + parse_trait_sig::{MethodError, TypeTransform}, syn_utils::{iter_path, iter_type}, }; @@ -161,7 +161,7 @@ impl TypeConverter<'_> { pub fn dynamize_function_bounds( generics: &mut Generics, type_converter: &TypeConverter, -) -> Result<HashMap<Ident, Vec<TypeTransform>>, (Span, MethodParseError)> { +) -> Result<HashMap<Ident, Vec<TypeTransform>>, (Span, MethodError)> { let mut type_param_transforms = HashMap::new(); for type_param in generics.type_params_mut() { @@ -202,7 +202,7 @@ pub fn dynamize_function_bounds( { return Err(( assoc_type.span(), - MethodParseError::UnconvertibleAssocTypeInWhereClause, + MethodError::UnconvertibleAssocTypeInWhereClause, )); } @@ -214,7 +214,7 @@ pub fn dynamize_function_bounds( { return Err(( assoc_type.span(), - MethodParseError::UnconvertibleAssocTypeInWhereClause, + MethodError::UnconvertibleAssocTypeInWhereClause, )); } } @@ -231,7 +231,7 @@ fn dynamize_trait_bound( type_converter: &TypeConverter, type_ident: &Ident, type_param_transforms: &mut HashMap<Ident, Vec<TypeTransform>>, -) -> Result<(), (Span, MethodParseError)> { +) -> Result<(), (Span, MethodError)> { if bound.path.segments.len() == 1 { let segment = &mut bound.path.segments[0]; @@ -244,10 +244,10 @@ fn dynamize_trait_bound( transforms.push(ret_type); } Err(TransformError::UnconvertibleAssocType(span)) => { - return Err((span, MethodParseError::UnconvertibleAssocType)); + return Err((span, MethodError::UnconvertibleAssocType)); } Err(TransformError::AssocTypeInUnsupportedType(span)) => { - return Err((span, MethodParseError::UnconvertibleAssocTypeInFnInput)); + return Err((span, MethodError::UnconvertibleAssocTypeInFnInput)); } } } @@ -261,10 +261,7 @@ fn dynamize_trait_bound( .filter_map(filter_map_assoc_paths) .next() { - return Err(( - path.span(), - MethodParseError::UnconvertibleAssocTypeInTraitBound, - )); + return Err((path.span(), MethodError::UnconvertibleAssocTypeInTraitBound)); } Ok(()) } |