@@ -224,7 +224,7 @@ impl HirDisplay for Struct {
224
224
StructKind :: Record => {
225
225
let has_where_clause = write_where_clause ( def_id, f) ?;
226
226
if let Some ( limit) = f. entity_limit {
227
- display_fields ( & self . fields ( f. db ) , has_where_clause, limit, false , f) ?;
227
+ write_fields ( & self . fields ( f. db ) , has_where_clause, limit, false , f) ?;
228
228
}
229
229
}
230
230
StructKind :: Unit => _ = write_where_clause ( def_id, f) ?,
@@ -244,7 +244,7 @@ impl HirDisplay for Enum {
244
244
245
245
let has_where_clause = write_where_clause ( def_id, f) ?;
246
246
if let Some ( limit) = f. entity_limit {
247
- display_variants ( & self . variants ( f. db ) , has_where_clause, limit, f) ?;
247
+ write_variants ( & self . variants ( f. db ) , has_where_clause, limit, f) ?;
248
248
}
249
249
250
250
Ok ( ( ) )
@@ -261,13 +261,13 @@ impl HirDisplay for Union {
261
261
262
262
let has_where_clause = write_where_clause ( def_id, f) ?;
263
263
if let Some ( limit) = f. entity_limit {
264
- display_fields ( & self . fields ( f. db ) , has_where_clause, limit, false , f) ?;
264
+ write_fields ( & self . fields ( f. db ) , has_where_clause, limit, false , f) ?;
265
265
}
266
266
Ok ( ( ) )
267
267
}
268
268
}
269
269
270
- fn display_fields (
270
+ fn write_fields (
271
271
fields : & [ Field ] ,
272
272
has_where_clause : bool ,
273
273
limit : usize ,
@@ -278,11 +278,7 @@ fn display_fields(
278
278
let ( indent, separator) = if in_line { ( "" , ' ' ) } else { ( " " , '\n' ) } ;
279
279
f. write_char ( if !has_where_clause { ' ' } else { separator } ) ?;
280
280
if count == 0 {
281
- if fields. is_empty ( ) {
282
- f. write_str ( "{}" ) ?;
283
- } else {
284
- f. write_str ( "{ /* … */ }" ) ?;
285
- }
281
+ f. write_str ( if fields. is_empty ( ) { "{}" } else { "{ /* … */ }" } ) ?;
286
282
} else {
287
283
f. write_char ( '{' ) ?;
288
284
@@ -291,14 +287,11 @@ fn display_fields(
291
287
for field in & fields[ ..count] {
292
288
f. write_str ( indent) ?;
293
289
field. hir_fmt ( f) ?;
294
- f. write_char ( ',' ) ?;
295
- f. write_char ( separator) ?;
290
+ write ! ( f, ",{separator}" ) ?;
296
291
}
297
292
298
293
if fields. len ( ) > count {
299
- f. write_str ( indent) ?;
300
- f. write_str ( "/* … */" ) ?;
301
- f. write_char ( separator) ?;
294
+ write ! ( f, "{indent}/* … */{separator}" ) ?;
302
295
}
303
296
}
304
297
@@ -308,7 +301,7 @@ fn display_fields(
308
301
Ok ( ( ) )
309
302
}
310
303
311
- fn display_variants (
304
+ fn write_variants (
312
305
variants : & [ Variant ] ,
313
306
has_where_clause : bool ,
314
307
limit : usize ,
@@ -317,30 +310,22 @@ fn display_variants(
317
310
let count = variants. len ( ) . min ( limit) ;
318
311
f. write_char ( if !has_where_clause { ' ' } else { '\n' } ) ?;
319
312
if count == 0 {
320
- if variants. is_empty ( ) {
321
- f. write_str ( "{}" ) ?;
322
- } else {
323
- f. write_str ( "{ /* … */ }" ) ?;
324
- }
313
+ let variants = if variants. is_empty ( ) { "{}" } else { "{ /* … */ }" } ;
314
+ f. write_str ( variants) ?;
325
315
} else {
326
316
f. write_str ( "{\n " ) ?;
327
317
for variant in & variants[ ..count] {
328
- f. write_str ( " " ) ?;
329
- write ! ( f, "{}" , variant. name( f. db) . display( f. db. upcast( ) ) ) ?;
318
+ write ! ( f, " {}" , variant. name( f. db) . display( f. db. upcast( ) ) ) ?;
330
319
match variant. kind ( f. db ) {
331
320
StructKind :: Tuple => {
332
- if variant. fields ( f. db ) . is_empty ( ) {
333
- f. write_str ( "()" ) ?;
334
- } else {
335
- f. write_str ( "( /* … */ )" ) ?;
336
- }
321
+ let fields_str =
322
+ if variant. fields ( f. db ) . is_empty ( ) { "()" } else { "( /* … */ )" } ;
323
+ f. write_str ( fields_str) ?;
337
324
}
338
325
StructKind :: Record => {
339
- if variant. fields ( f. db ) . is_empty ( ) {
340
- f. write_str ( " {}" ) ?;
341
- } else {
342
- f. write_str ( " { /* … */ }" ) ?;
343
- }
326
+ let fields_str =
327
+ if variant. fields ( f. db ) . is_empty ( ) { " {}" } else { " { /* … */ }" } ;
328
+ f. write_str ( fields_str) ?;
344
329
}
345
330
StructKind :: Unit => { }
346
331
}
@@ -393,7 +378,7 @@ impl HirDisplay for Variant {
393
378
}
394
379
VariantData :: Record ( _) => {
395
380
if let Some ( limit) = f. entity_limit {
396
- display_fields ( & self . fields ( f. db ) , false , limit, true , f) ?;
381
+ write_fields ( & self . fields ( f. db ) , false , limit, true , f) ?;
397
382
}
398
383
}
399
384
}
0 commit comments