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/lib.rs | |
parent | 7489a3c2246e7ea2483446dd2ed3fdbfaf462c1a (diff) |
return error for unused #[convert]s
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -97,6 +97,7 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { assoc_type_conversions: HashMap::new(), collections: method_attrs.collections, type_conversions: method_attrs.type_conversions, + used_conversions: Default::default(), }; for item in &original_trait.items { @@ -127,7 +128,7 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { if let TraitItem::Method(method) = item { let mut signature = method.sig.clone(); - match convert_trait_signature(&mut signature, &type_converter) { + match convert_trait_signature(&mut signature, &mut type_converter) { Ok(parsed_method) => objectifiable_methods.push((signature, parsed_method)), Err((span, err)) => match err { MethodError::NonDispatchableMethod => continue, @@ -181,6 +182,13 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { } } + for ty in type_converter.type_conversions.keys() { + if !type_converter.used_conversions.contains(ty) { + // FUTURE: relax to warning once proc_macro::Diagnostic is stable + return abort!(ty.span(), "unused conversion"); + } + } + let mut method_impls: Vec<ImplItemMethod> = Vec::new(); let mut dyn_trait = ItemTrait { |