diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-24 19:30:32 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-24 19:37:33 +0100 |
commit | 73b1ca899858b7079bec54a6e4f29941cbb8d0bd (patch) | |
tree | ff30b195bf51b6e217fd81cdb0190fc3be8e07e4 /src/transform.rs | |
parent | dcf7a21372f22011a6081c26ade0a78fb2f10b5a (diff) |
better error message for <Self as Foo>::X
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 15 |
1 files changed, 14 insertions, 1 deletions
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); } |