diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-25 13:04:38 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-25 13:40:30 +0100 |
commit | 88f33dee26815c3382bfb18c800f3f54b6397e20 (patch) | |
tree | 9f8a36a62ff0b6d64ffebe3fed04c8e1d37947a9 /src/transform.rs | |
parent | dc568083381d2073f0cfcfad8fa58158bd5bf811 (diff) |
also detect <Self as Foo>::X in generic type args
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/transform.rs b/src/transform.rs index 39d3cab..74ab9e6 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -3,14 +3,13 @@ use std::collections::HashMap; use proc_macro2::Span; use quote::quote; use syn::{ - spanned::Spanned, GenericArgument, Generics, Ident, PathArguments, QSelf, TraitBound, Type, + spanned::Spanned, GenericArgument, Generics, Ident, PathArguments, TraitBound, Type, TypeParamBound, TypePath, TypeReference, TypeTraitObject, WherePredicate, }; use crate::{ filter_map_assoc_paths, match_assoc_type, parse_assoc_type::{BoxType, DestType}, - path_is_assoc_type, syn_utils::{iter_path, iter_type, type_arguments_mut}, trait_sig::{MethodError, TypeTransform}, }; @@ -59,17 +58,6 @@ 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(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); } @@ -125,7 +113,19 @@ impl TypeConverter<'_> { } } - if let Type::Path(TypePath { path, qself: None }) = type_ { + if let Type::Path(TypePath { + qself: Some(qself), .. + }) = type_ + { + if let Type::Path(self_path) = qself.ty.as_ref() { + if self_path.path.segments[0].ident == "Self" { + return Err(( + self_path.span(), + TransformError::QualifiedSelfAssociatedType, + )); + } + } + } else if let Type::Path(TypePath { path, qself: None }) = type_ { if path.segments[0].ident == "Self" { if path.segments.len() == 2 { let ident = &path.segments.last().unwrap().ident; |