aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-24 19:30:32 +0100
committerMartin Fischer <martin@push-f.com>2021-11-24 19:37:33 +0100
commit73b1ca899858b7079bec54a6e4f29941cbb8d0bd (patch)
treeff30b195bf51b6e217fd81cdb0190fc3be8e07e4 /src
parentdcf7a21372f22011a6081c26ade0a78fb2f10b5a (diff)
better error message for <Self as Foo>::X
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs3
-rw-r--r--src/transform.rs15
2 files changed, 17 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 277720e..00b9772 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -229,6 +229,9 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream {
n
)
}
+ MethodError::Transform(TransformError::QualifiedSelfAssociatedType) => {
+ return abort!(span, "dynamize does not support associated types of a qualified Self")
+ }
MethodError::UnconvertedAssocType => {
return abort!(span, "dynamize does not support associated types here")
}
diff --git a/src/transform.rs b/src/transform.rs
index 8de4c96..594d383 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
use proc_macro2::Span;
use quote::quote;
use syn::{
- spanned::Spanned, GenericArgument, Generics, Ident, PathArguments, TraitBound, Type,
+ spanned::Spanned, GenericArgument, Generics, Ident, PathArguments, QSelf, TraitBound, Type,
TypeParamBound, TypePath, TypeReference, TypeTraitObject, WherePredicate,
};
@@ -11,6 +11,7 @@ use crate::{
filter_map_assoc_paths, match_assoc_type,
parse_assoc_type::{BoxType, DestType},
parse_trait_sig::{MethodError, TypeTransform},
+ path_is_assoc_type,
syn_utils::{iter_path, iter_type, type_arguments_mut},
};
@@ -26,6 +27,7 @@ pub enum TransformError {
UnsupportedType,
ExpectedAtLeastNTypes(usize),
AssocTypeAfterFirstNTypes(usize, Ident),
+ QualifiedSelfAssociatedType,
}
impl TypeConverter<'_> {
@@ -57,6 +59,17 @@ impl TypeConverter<'_> {
}
pub fn convert_type(&self, type_: &mut Type) -> Result<TypeTransform, (Span, TransformError)> {
+ if let Type::Path(TypePath {
+ qself: Some(QSelf { ty, .. }),
+ ..
+ }) = type_
+ {
+ if let Type::Path(TypePath { qself: None, path }) = ty.as_ref() {
+ if path_is_assoc_type(path) {
+ return Err((path.span(), TransformError::QualifiedSelfAssociatedType));
+ }
+ }
+ }
if !iter_type(type_).any(match_assoc_type) {
return Ok(TypeTransform::NoOp);
}