aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-22 12:57:53 +0100
committerMartin Fischer <martin@push-f.com>2021-11-22 13:03:47 +0100
commit684d7e5873aa0b6423e167124fd8c72e02173ba2 (patch)
treee53af9b8b4abcd815cfdac5871d145ef73ac4d39 /src/lib.rs
parent890247746e74e015acbb290c925284c5047a580c (diff)
better errors for type arguments of collections
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 67c1223..1a84a09 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -53,9 +53,11 @@ mod syn_utils;
mod transform;
macro_rules! abort {
- ($span:expr, $message:literal) => {
- quote_spanned! {$span => compile_error!($message);}.into()
- };
+ ($span:expr, $message:literal $(,$args:tt)*) => {{
+ let msg = format!($message $(,$args)*);
+ let tokens = quote_spanned! {$span => compile_error!(#msg);}.into();
+ tokens
+ }};
}
#[proc_macro_attribute]
@@ -119,6 +121,21 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream {
MethodError::Transform(TransformError::UnsupportedType) => {
return abort!(span, "dynamize does not know how to convert this type")
}
+ MethodError::Transform(TransformError::ExpectedAtLeastNTypes(n)) => {
+ return abort!(
+ span,
+ "dynamize expects at least {} generic type arguments for this type",
+ n
+ )
+ }
+ MethodError::Transform(TransformError::AssocTypeAfterFirstNTypes(n, ident)) => {
+ return abort!(
+ span,
+ "for {} dynamize supports associated types only within the first {} generic type parameters",
+ ident,
+ n
+ )
+ }
MethodError::UnconvertedAssocType => {
return abort!(span, "dynamize does not support associated types here")
}