@@ -1154,6 +1154,45 @@ pub(crate) fn format_trait(
1154
1154
}
1155
1155
}
1156
1156
1157
+ pub ( crate ) struct TraitAliasBounds < ' a > {
1158
+ generic_bounds : & ' a ast:: GenericBounds ,
1159
+ generics : & ' a ast:: Generics ,
1160
+ }
1161
+
1162
+ impl < ' a > Rewrite for TraitAliasBounds < ' a > {
1163
+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
1164
+ let generic_bounds_str = self . generic_bounds . rewrite ( context, shape) ?;
1165
+
1166
+ let mut option = WhereClauseOption :: new ( true , WhereClauseSpace :: None ) ;
1167
+ option. allow_single_line ( ) ;
1168
+
1169
+ let where_str = rewrite_where_clause (
1170
+ context,
1171
+ & self . generics . where_clause ,
1172
+ context. config . brace_style ( ) ,
1173
+ shape,
1174
+ Density :: Compressed ,
1175
+ ";" ,
1176
+ None ,
1177
+ self . generics . where_clause . span . lo ( ) ,
1178
+ option,
1179
+ ) ?;
1180
+
1181
+ let fits_single_line = !generic_bounds_str. contains ( '\n' )
1182
+ && !where_str. contains ( '\n' )
1183
+ && generic_bounds_str. len ( ) + where_str. len ( ) + 1 <= shape. width ;
1184
+ let space = if generic_bounds_str. is_empty ( ) || where_str. is_empty ( ) {
1185
+ Cow :: from ( "" )
1186
+ } else if fits_single_line {
1187
+ Cow :: from ( " " )
1188
+ } else {
1189
+ shape. indent . to_string_with_newline ( & context. config )
1190
+ } ;
1191
+
1192
+ Some ( format ! ( "{}{}{}" , generic_bounds_str, space, where_str) )
1193
+ }
1194
+ }
1195
+
1157
1196
pub ( crate ) fn format_trait_alias (
1158
1197
context : & RewriteContext < ' _ > ,
1159
1198
ident : ast:: Ident ,
@@ -1169,7 +1208,11 @@ pub(crate) fn format_trait_alias(
1169
1208
let vis_str = format_visibility ( context, vis) ;
1170
1209
let lhs = format ! ( "{}trait {} =" , vis_str, generics_str) ;
1171
1210
// 1 = ";"
1172
- rewrite_assign_rhs ( context, lhs, generic_bounds, shape. sub_width ( 1 ) ?) . map ( |s| s + ";" )
1211
+ let trait_alias_bounds = TraitAliasBounds {
1212
+ generics,
1213
+ generic_bounds,
1214
+ } ;
1215
+ rewrite_assign_rhs ( context, lhs, & trait_alias_bounds, shape. sub_width ( 1 ) ?) . map ( |s| s + ";" )
1173
1216
}
1174
1217
1175
1218
fn format_unit_struct (
0 commit comments