diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-26 10:27:50 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-26 11:45:53 +0100 |
commit | d37cf6a72e633afb10ec78bdbeec6631d601adfe (patch) | |
tree | 1db3a4b735382c65c0feed07a3328cdd059c4bd5 /src/transform.rs | |
parent | 7489a3c2246e7ea2483446dd2ed3fdbfaf462c1a (diff) |
return error for unused #[convert]s
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/transform.rs b/src/transform.rs index ae345c8..c56bec1 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -1,4 +1,7 @@ -use std::{collections::HashMap, rc::Rc}; +use std::{ + collections::{HashMap, HashSet}, + rc::Rc, +}; use proc_macro2::Span; use quote::quote; @@ -20,6 +23,7 @@ pub struct TypeConverter { pub collections: HashMap<Ident, usize>, pub trait_ident: Ident, pub type_conversions: HashMap<Type, Rc<Convert>>, + pub used_conversions: HashSet<Type>, } #[derive(Debug)] @@ -60,8 +64,12 @@ impl TypeConverter { None } - pub fn convert_type(&self, type_: &mut Type) -> Result<TypeTransform, (Span, TransformError)> { + pub fn convert_type( + &mut self, + type_: &mut Type, + ) -> Result<TypeTransform, (Span, TransformError)> { if let Some(conv) = self.type_conversions.get(type_) { + self.used_conversions.insert(conv.original_type.clone()); *type_ = conv.dest_type.clone(); return Ok(TypeTransform::Verbatim(conv.clone())); } @@ -223,7 +231,7 @@ impl TypeConverter { pub fn dynamize_function_bounds( generics: &mut Generics, - type_converter: &TypeConverter, + type_converter: &mut TypeConverter, ) -> Result<HashMap<Ident, Vec<TypeTransform>>, (Span, MethodError)> { let mut type_param_transforms = HashMap::new(); @@ -285,7 +293,7 @@ pub fn dynamize_function_bounds( fn dynamize_trait_bound( bound: &mut TraitBound, - type_converter: &TypeConverter, + type_converter: &mut TypeConverter, type_ident: &Ident, type_param_transforms: &mut HashMap<Ident, Vec<TypeTransform>>, ) -> Result<(), (Span, MethodError)> { |