@@ -12,7 +12,7 @@ use syn::visit_mut::{self, VisitMut};
1212use syn:: {
1313 parse_quote, parse_quote_spanned, Attribute , Block , FnArg , GenericArgument , GenericParam ,
1414 Generics , Ident , ImplItem , Lifetime , LifetimeParam , Pat , PatIdent , PathArguments , Receiver ,
15- ReturnType , Signature , Token , TraitItem , Type , TypeInfer , TypePath , WhereClause ,
15+ ReceiverKind , ReturnType , Signature , Token , TraitItem , Type , TypeInfer , TypePath , WhereClause ,
1616} ;
1717
1818impl ToTokens for Item {
@@ -248,30 +248,37 @@ fn transform_sig(
248248 let bounds: & [ InferredBound ] = if is_local {
249249 & [ ]
250250 } else if let Some ( receiver) = sig. receiver ( ) {
251- match receiver. ty . as_ref ( ) {
252- // self: &Self
253- Type :: Reference ( ty) if ty. mutability . is_none ( ) => & [ InferredBound :: Sync ] ,
254- // self: Arc<Self>
255- Type :: Path ( ty)
256- if {
257- let segment = ty. path . segments . last ( ) . unwrap ( ) ;
258- segment. ident == "Arc"
259- && match & segment. arguments {
260- PathArguments :: AngleBracketed ( arguments) => {
261- arguments. args . len ( ) == 1
262- && match & arguments. args [ 0 ] {
263- GenericArgument :: Type ( Type :: Path ( arg) ) => {
264- arg. path . is_ident ( "Self" )
251+ match & receiver. kind {
252+ // &self
253+ ReceiverKind :: Reference ( _ampersand, _lifetime, None :: < Token ! [ mut ] > ) => {
254+ & [ InferredBound :: Sync ]
255+ }
256+ ReceiverKind :: Typed ( _colon, ty) => match ty. as_ref ( ) {
257+ // self: &Self
258+ Type :: Reference ( ty) if ty. mutability . is_none ( ) => & [ InferredBound :: Sync ] ,
259+ // self: Arc<Self>
260+ Type :: Path ( ty)
261+ if {
262+ let segment = ty. path . segments . last ( ) . unwrap ( ) ;
263+ segment. ident == "Arc"
264+ && match & segment. arguments {
265+ PathArguments :: AngleBracketed ( arguments) => {
266+ arguments. args . len ( ) == 1
267+ && match & arguments. args [ 0 ] {
268+ GenericArgument :: Type ( Type :: Path ( arg) ) => {
269+ arg. path . is_ident ( "Self" )
270+ }
271+ _ => false ,
265272 }
266- _ => false ,
267- }
273+ }
274+ _ => false ,
268275 }
269- _ => false ,
270- }
271- } =>
272- {
273- & [ InferredBound :: Sync , InferredBound :: Send ]
274- }
276+ } =>
277+ {
278+ & [ InferredBound :: Sync , InferredBound :: Send ]
279+ }
280+ _ => & [ InferredBound :: Send ] ,
281+ } ,
275282 _ => & [ InferredBound :: Send ] ,
276283 }
277284 } else {
@@ -293,9 +300,7 @@ fn transform_sig(
293300 for ( i, arg) in sig. inputs . iter_mut ( ) . enumerate ( ) {
294301 match arg {
295302 FnArg :: Receiver ( receiver) => {
296- if receiver. reference . is_none ( ) {
297- receiver. mutability = None ;
298- }
303+ receiver. mutability = None ;
299304 }
300305 FnArg :: Typed ( arg) => {
301306 if match * arg. ty {
@@ -493,6 +498,7 @@ fn replace_impl_trait_with_infer(ty: &mut Type) {
493498 fn visit_type_mut ( & mut self , ty : & mut Type ) {
494499 if let Type :: ImplTrait ( impl_trait) = ty {
495500 * ty = Type :: Infer ( TypeInfer {
501+ attrs : Vec :: new ( ) ,
496502 underscore_token : Token ! [ _] ( impl_trait. impl_token . span ) ,
497503 } ) ;
498504 }
0 commit comments