Skip to content

Commit 687889c

Browse files
committed
internal: simplify and rename display_xxx to write_xxx for consistency
1 parent 445e886 commit 687889c

File tree

1 file changed

+18
-33
lines changed

1 file changed

+18
-33
lines changed

src/tools/rust-analyzer/crates/hir/src/display.rs

+18-33
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl HirDisplay for Struct {
224224
StructKind::Record => {
225225
let has_where_clause = write_where_clause(def_id, f)?;
226226
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)?;
228228
}
229229
}
230230
StructKind::Unit => _ = write_where_clause(def_id, f)?,
@@ -244,7 +244,7 @@ impl HirDisplay for Enum {
244244

245245
let has_where_clause = write_where_clause(def_id, f)?;
246246
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)?;
248248
}
249249

250250
Ok(())
@@ -261,13 +261,13 @@ impl HirDisplay for Union {
261261

262262
let has_where_clause = write_where_clause(def_id, f)?;
263263
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)?;
265265
}
266266
Ok(())
267267
}
268268
}
269269

270-
fn display_fields(
270+
fn write_fields(
271271
fields: &[Field],
272272
has_where_clause: bool,
273273
limit: usize,
@@ -278,11 +278,7 @@ fn display_fields(
278278
let (indent, separator) = if in_line { ("", ' ') } else { (" ", '\n') };
279279
f.write_char(if !has_where_clause { ' ' } else { separator })?;
280280
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 { "{ /* … */ }" })?;
286282
} else {
287283
f.write_char('{')?;
288284

@@ -291,14 +287,11 @@ fn display_fields(
291287
for field in &fields[..count] {
292288
f.write_str(indent)?;
293289
field.hir_fmt(f)?;
294-
f.write_char(',')?;
295-
f.write_char(separator)?;
290+
write!(f, ",{separator}")?;
296291
}
297292

298293
if fields.len() > count {
299-
f.write_str(indent)?;
300-
f.write_str("/* … */")?;
301-
f.write_char(separator)?;
294+
write!(f, "{indent}/* … */{separator}")?;
302295
}
303296
}
304297

@@ -308,7 +301,7 @@ fn display_fields(
308301
Ok(())
309302
}
310303

311-
fn display_variants(
304+
fn write_variants(
312305
variants: &[Variant],
313306
has_where_clause: bool,
314307
limit: usize,
@@ -317,30 +310,22 @@ fn display_variants(
317310
let count = variants.len().min(limit);
318311
f.write_char(if !has_where_clause { ' ' } else { '\n' })?;
319312
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)?;
325315
} else {
326316
f.write_str("{\n")?;
327317
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()))?;
330319
match variant.kind(f.db) {
331320
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)?;
337324
}
338325
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)?;
344329
}
345330
StructKind::Unit => {}
346331
}
@@ -393,7 +378,7 @@ impl HirDisplay for Variant {
393378
}
394379
VariantData::Record(_) => {
395380
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)?;
397382
}
398383
}
399384
}

0 commit comments

Comments
 (0)