@@ -9,9 +9,9 @@ use std::mem;
9
9
use syn:: punctuated:: Punctuated ;
10
10
use syn:: visit_mut:: { self , VisitMut } ;
11
11
use syn:: {
12
- parse_quote, parse_quote_spanned, Attribute , Block , FnArg , GenericParam , Generics , Ident ,
13
- ImplItem , Lifetime , LifetimeDef , Pat , PatIdent , Receiver , ReturnType , Signature , Stmt , Token ,
14
- TraitItem , Type , TypePath , WhereClause ,
12
+ parse_quote, parse_quote_spanned, Attribute , Block , FnArg , GenericArgument , GenericParam ,
13
+ Generics , Ident , ImplItem , Lifetime , LifetimeDef , Pat , PatIdent , PathArguments , Receiver ,
14
+ ReturnType , Signature , Stmt , Token , TraitItem , Type , TypePath , WhereClause ,
15
15
} ;
16
16
17
17
impl ToTokens for Item {
@@ -229,23 +229,46 @@ fn transform_sig(
229
229
. push ( parse_quote_spanned ! ( default_span=> ' async_trait) ) ;
230
230
231
231
if has_self {
232
- let bounds = match sig. inputs . iter ( ) . next ( ) {
232
+ let bounds: & [ InferredBound ] = match sig. inputs . iter ( ) . next ( ) {
233
233
Some ( FnArg :: Receiver ( Receiver {
234
234
reference : Some ( _) ,
235
235
mutability : None ,
236
236
..
237
- } ) ) => [ InferredBound :: Sync ] ,
237
+ } ) ) => & [ InferredBound :: Sync ] ,
238
238
Some ( FnArg :: Typed ( arg) )
239
- if match ( arg. pat . as_ref ( ) , arg. ty . as_ref ( ) ) {
240
- ( Pat :: Ident ( pat) , Type :: Reference ( ty) ) => {
241
- pat. ident == "self" && ty. mutability . is_none ( )
242
- }
239
+ if match arg. pat . as_ref ( ) {
240
+ Pat :: Ident ( pat) => pat. ident == "self" ,
243
241
_ => false ,
244
242
} =>
245
243
{
246
- [ InferredBound :: Sync ]
244
+ match arg. ty . as_ref ( ) {
245
+ // self: &Self
246
+ Type :: Reference ( ty) if ty. mutability . is_none ( ) => & [ InferredBound :: Sync ] ,
247
+ // self: Arc<Self>
248
+ Type :: Path ( ty)
249
+ if {
250
+ let segment = ty. path . segments . last ( ) . unwrap ( ) ;
251
+ segment. ident == "Arc"
252
+ && match & segment. arguments {
253
+ PathArguments :: AngleBracketed ( arguments) => {
254
+ arguments. args . len ( ) == 1
255
+ && match & arguments. args [ 0 ] {
256
+ GenericArgument :: Type ( Type :: Path ( arg) ) => {
257
+ arg. path . is_ident ( "Self" )
258
+ }
259
+ _ => false ,
260
+ }
261
+ }
262
+ _ => false ,
263
+ }
264
+ } =>
265
+ {
266
+ & [ InferredBound :: Sync , InferredBound :: Send ]
267
+ }
268
+ _ => & [ InferredBound :: Send ] ,
269
+ }
247
270
}
248
- _ => [ InferredBound :: Send ] ,
271
+ _ => & [ InferredBound :: Send ] ,
249
272
} ;
250
273
251
274
let bounds = bounds. iter ( ) . filter_map ( |bound| {
0 commit comments