From 066f06ec0df881f70c387053cbbb16f1e990fd9f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 29 Nov 2022 00:02:05 -0800 Subject: [PATCH] Match specifically Arc, not any other Arc --- src/expand.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/expand.rs b/src/expand.rs index ad4118d..53918cb 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -9,9 +9,9 @@ use std::mem; use syn::punctuated::Punctuated; use syn::visit_mut::{self, VisitMut}; use syn::{ - parse_quote, parse_quote_spanned, Attribute, Block, FnArg, GenericParam, Generics, Ident, - ImplItem, Lifetime, LifetimeDef, Pat, PatIdent, Receiver, ReturnType, Signature, Stmt, Token, - TraitItem, Type, TypePath, WhereClause, + parse_quote, parse_quote_spanned, Attribute, Block, FnArg, GenericArgument, GenericParam, + Generics, Ident, ImplItem, Lifetime, LifetimeDef, Pat, PatIdent, PathArguments, Receiver, + ReturnType, Signature, Stmt, Token, TraitItem, Type, TypePath, WhereClause, }; impl ToTokens for Item { @@ -242,8 +242,27 @@ fn transform_sig( } => { match arg.ty.as_ref() { + // self: &Self Type::Reference(ty) if ty.mutability.is_none() => &[InferredBound::Sync], - Type::Path(ty) if ty.path.segments.last().unwrap().ident == "Arc" => { + // self: Arc + Type::Path(ty) + if { + let segment = ty.path.segments.last().unwrap(); + segment.ident == "Arc" + && match &segment.arguments { + PathArguments::AngleBracketed(arguments) => { + arguments.args.len() == 1 + && match &arguments.args[0] { + GenericArgument::Type(Type::Path(arg)) => { + arg.path.is_ident("Self") + } + _ => false, + } + } + _ => false, + } + } => + { &[InferredBound::Sync, InferredBound::Send] } _ => &[InferredBound::Send],