@@ -444,7 +444,7 @@ impl Rewrite for ast::WherePredicate {
444444 let type_str = bounded_ty. rewrite ( context, shape) ?;
445445 let colon = type_bound_colon ( context) . trim_end ( ) ;
446446 let lhs = if let Some ( lifetime_str) =
447- rewrite_lifetime_param ( context, shape, bound_generic_params)
447+ rewrite_generic_params ( context, shape, bound_generic_params)
448448 {
449449 format ! ( "for<{}> {}{}" , lifetime_str, type_str, colon)
450450 } else {
@@ -590,7 +590,7 @@ impl Rewrite for ast::GenericParam {
590590impl Rewrite for ast:: PolyTraitRef {
591591 fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
592592 if let Some ( lifetime_str) =
593- rewrite_lifetime_param ( context, shape, & self . bound_generic_params )
593+ rewrite_generic_params ( context, shape, & self . bound_generic_params )
594594 {
595595 // 6 is "for<> ".len()
596596 let extra_offset = lifetime_str. len ( ) + 6 ;
@@ -771,7 +771,7 @@ fn rewrite_bare_fn(
771771
772772 let mut result = String :: with_capacity ( 128 ) ;
773773
774- if let Some ( ref lifetime_str) = rewrite_lifetime_param ( context, shape, & bare_fn. generic_params )
774+ if let Some ( ref lifetime_str) = rewrite_generic_params ( context, shape, & bare_fn. generic_params )
775775 {
776776 result. push_str ( "for<" ) ;
777777 // 6 = "for<> ".len(), 4 = "for<".
@@ -900,24 +900,20 @@ pub(crate) fn can_be_overflowed_type(
900900 }
901901}
902902
903- /// Returns `None` if there is no `LifetimeDef` in the given generic parameters.
904- fn rewrite_lifetime_param (
903+ /// Returns rewritten params separated by commas, or `None` if there are no params or a param
904+ /// failed to be rewritten.
905+ fn rewrite_generic_params (
905906 context : & RewriteContext < ' _ > ,
906907 shape : Shape ,
907908 generic_params : & [ ast:: GenericParam ] ,
908909) -> Option < String > {
910+ if generic_params. is_empty ( ) {
911+ return None ;
912+ }
909913 let result = generic_params
910914 . iter ( )
911- . filter ( |p| match p. kind {
912- ast:: GenericParamKind :: Lifetime => true ,
913- _ => false ,
914- } )
915915 . map ( |lt| lt. rewrite ( context, shape) )
916916 . collect :: < Option < Vec < _ > > > ( ) ?
917917 . join ( ", " ) ;
918- if result. is_empty ( ) {
919- None
920- } else {
921- Some ( result)
922- }
918+ Some ( result)
923919}
0 commit comments