@@ -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 , TypePath , WhereClause ,
15+ ReturnType , Signature , Token , TraitItem , Type , TypeInfer , TypePath , WhereClause ,
1616} ;
1717
1818impl ToTokens for Item {
@@ -410,6 +410,8 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
410410 quote ! ( #( #decls) * { #( #stmts) * } )
411411 }
412412 } else {
413+ let mut ret = ret. clone ( ) ;
414+ replace_impl_trait_with_infer ( & mut ret) ;
413415 quote ! {
414416 if let :: core:: option:: Option :: Some ( __ret) = :: core:: option:: Option :: None :: <#ret> {
415417 #[ allow( unreachable_code) ]
@@ -475,3 +477,20 @@ fn where_clause_or_default(clause: &mut Option<WhereClause>) -> &mut WhereClause
475477 predicates : Punctuated :: new ( ) ,
476478 } )
477479}
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