@@ -635,6 +635,18 @@ impl Clean<Generics> for hir::Generics<'_> {
635635 _ => false ,
636636 }
637637 }
638+ /// This can happen for `async fn`, e.g. `async fn f<'_>(&'_ self)`.
639+ ///
640+ /// See [`lifetime_to_generic_param`] in [`rustc_ast_lowering`] for more information.
641+ ///
642+ /// [`lifetime_to_generic_param`]: rustc_ast_lowering::LoweringContext::lifetime_to_generic_param
643+ fn is_elided_lifetime ( param : & hir:: GenericParam < ' _ > ) -> bool {
644+ match param. kind {
645+ hir:: GenericParamKind :: Lifetime { kind : hir:: LifetimeParamKind :: Elided } => true ,
646+ _ => false ,
647+ }
648+ }
649+
638650 let impl_trait_params = self
639651 . params
640652 . iter ( )
@@ -653,7 +665,7 @@ impl Clean<Generics> for hir::Generics<'_> {
653665 . collect :: < Vec < _ > > ( ) ;
654666
655667 let mut params = Vec :: with_capacity ( self . params . len ( ) ) ;
656- for p in self . params . iter ( ) . filter ( |p| !is_impl_trait ( p) ) {
668+ for p in self . params . iter ( ) . filter ( |p| !is_impl_trait ( p) && ! is_elided_lifetime ( p ) ) {
657669 let p = p. clean ( cx) ;
658670 params. push ( p) ;
659671 }
@@ -1433,7 +1445,16 @@ impl Clean<Type> for hir::Ty<'_> {
14331445 TyKind :: Never => Never ,
14341446 TyKind :: Ptr ( ref m) => RawPointer ( m. mutbl , box m. ty . clean ( cx) ) ,
14351447 TyKind :: Rptr ( ref l, ref m) => {
1436- let lifetime = if l. is_elided ( ) { None } else { Some ( l. clean ( cx) ) } ;
1448+ // There are two times a `Fresh` lifetime can be created:
1449+ // 1. For `&'_ x`, written by the user. This corresponds to `lower_lifetime` in `rustc_ast_lowering`.
1450+ // 2. For `&x` as a parameter to an `async fn`. This corresponds to `elided_ref_lifetime in `rustc_ast_lowering`.
1451+ // See commit 749349fc9f7b12f212bca9ba2297e463328cb701 for more information.
1452+ // Ideally we would only hide the `'_` for case 2., but I don't know a way to distinguish it.
1453+ // Turning `fn f(&'_ self)` into `fn f(&self)` isn't the worst thing in the world, though;
1454+ // there's no case where it could cause the function to fail to compile.
1455+ let elided =
1456+ l. is_elided ( ) || matches ! ( l. name, LifetimeName :: Param ( ParamName :: Fresh ( _) ) ) ;
1457+ let lifetime = if elided { None } else { Some ( l. clean ( cx) ) } ;
14371458 BorrowedRef { lifetime, mutability : m. mutbl , type_ : box m. ty . clean ( cx) }
14381459 }
14391460 TyKind :: Slice ( ref ty) => Slice ( box ty. clean ( cx) ) ,
0 commit comments