@@ -12,7 +12,7 @@ use syn::visit_mut::{self, VisitMut};
12
12
use syn:: {
13
13
parse_quote, parse_quote_spanned, Attribute , Block , FnArg , GenericArgument , GenericParam ,
14
14
Generics , Ident , ImplItem , Lifetime , LifetimeParam , Pat , PatIdent , PathArguments , Receiver ,
15
- ReturnType , Signature , Token , TraitItem , Type , TypePath , WhereClause ,
15
+ ReturnType , Signature , Token , TraitItem , Type , TypeInfer , TypePath , WhereClause ,
16
16
} ;
17
17
18
18
impl ToTokens for Item {
@@ -410,6 +410,8 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
410
410
quote ! ( #( #decls) * { #( #stmts) * } )
411
411
}
412
412
} else {
413
+ let mut ret = ret. clone ( ) ;
414
+ replace_impl_trait_with_infer ( & mut ret) ;
413
415
quote ! {
414
416
if let :: core:: option:: Option :: Some ( __ret) = :: core:: option:: Option :: None :: <#ret> {
415
417
#[ allow( unreachable_code) ]
@@ -475,3 +477,20 @@ fn where_clause_or_default(clause: &mut Option<WhereClause>) -> &mut WhereClause
475
477
predicates : Punctuated :: new ( ) ,
476
478
} )
477
479
}
480
+
481
+ fn replace_impl_trait_with_infer ( ty : & mut Type ) {
482
+ struct ReplaceImplTraitWithInfer ;
483
+
484
+ impl VisitMut for ReplaceImplTraitWithInfer {
485
+ fn visit_type_mut ( & mut self , ty : & mut Type ) {
486
+ if let Type :: ImplTrait ( impl_trait) = ty {
487
+ * ty = Type :: Infer ( TypeInfer {
488
+ underscore_token : Token ! [ _] ( impl_trait. impl_token . span ) ,
489
+ } ) ;
490
+ }
491
+ visit_mut:: visit_type_mut ( self , ty) ;
492
+ }
493
+ }
494
+
495
+ ReplaceImplTraitWithInfer . visit_type_mut ( ty) ;
496
+ }
0 commit comments