Skip to content

Commit 78991b6

Browse files
committed
Inline and remove three pretty-printer methods.
They all have a single call site, aren't that big, and removing them avoids having to pass some `BoxMarker`s.
1 parent c0ca875 commit 78991b6

File tree

2 files changed

+37
-67
lines changed
  • compiler
    • rustc_ast_pretty/src/pprust/state
    • rustc_hir_pretty/src

2 files changed

+37
-67
lines changed

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+22-42
Original file line numberDiff line numberDiff line change
@@ -439,18 +439,8 @@ impl<'a> State<'a> {
439439
self.print_generic_params(&generics.params);
440440
self.print_where_clause(&generics.where_clause);
441441
self.space();
442-
self.print_variants(&enum_definition.variants, span, cb, ib)
443-
}
444-
445-
fn print_variants(
446-
&mut self,
447-
variants: &[ast::Variant],
448-
span: rustc_span::Span,
449-
cb: BoxMarker,
450-
ib: BoxMarker,
451-
) {
452442
self.bopen(ib);
453-
for v in variants {
443+
for v in enum_definition.variants.iter() {
454444
self.space_if_not_bol();
455445
self.maybe_print_comment(v.span.lo());
456446
self.print_outer_attributes(&v.attrs);
@@ -460,7 +450,7 @@ impl<'a> State<'a> {
460450
self.end(ib);
461451
self.maybe_print_trailing_comment(v.span, None);
462452
}
463-
let empty = variants.is_empty();
453+
let empty = enum_definition.variants.is_empty();
464454
self.bclose(span, empty, cb)
465455
}
466456

@@ -485,35 +475,6 @@ impl<'a> State<'a> {
485475
}
486476
}
487477

488-
pub(crate) fn print_record_struct_body(
489-
&mut self,
490-
fields: &[ast::FieldDef],
491-
span: rustc_span::Span,
492-
cb: BoxMarker,
493-
ib: BoxMarker,
494-
) {
495-
self.nbsp();
496-
self.bopen(ib);
497-
498-
let empty = fields.is_empty();
499-
if !empty {
500-
self.hardbreak_if_not_bol();
501-
502-
for field in fields {
503-
self.hardbreak_if_not_bol();
504-
self.maybe_print_comment(field.span.lo());
505-
self.print_outer_attributes(&field.attrs);
506-
self.print_visibility(&field.vis);
507-
self.print_ident(field.ident.unwrap());
508-
self.word_nbsp(":");
509-
self.print_type(&field.ty);
510-
self.word(",");
511-
}
512-
}
513-
514-
self.bclose(span, empty, cb);
515-
}
516-
517478
fn print_struct(
518479
&mut self,
519480
struct_def: &ast::VariantData,
@@ -547,7 +508,26 @@ impl<'a> State<'a> {
547508
}
548509
ast::VariantData::Struct { fields, .. } => {
549510
self.print_where_clause(&generics.where_clause);
550-
self.print_record_struct_body(fields, span, cb, ib);
511+
self.nbsp();
512+
self.bopen(ib);
513+
514+
let empty = fields.is_empty();
515+
if !empty {
516+
self.hardbreak_if_not_bol();
517+
518+
for field in fields {
519+
self.hardbreak_if_not_bol();
520+
self.maybe_print_comment(field.span.lo());
521+
self.print_outer_attributes(&field.attrs);
522+
self.print_visibility(&field.vis);
523+
self.print_ident(field.ident.unwrap());
524+
self.word_nbsp(":");
525+
self.print_type(&field.ty);
526+
self.word(",");
527+
}
528+
}
529+
530+
self.bclose(span, empty, cb);
551531
}
552532
}
553533
}

compiler/rustc_hir_pretty/src/lib.rs

+15-25
Original file line numberDiff line numberDiff line change
@@ -870,33 +870,23 @@ impl<'a> State<'a> {
870870
}
871871
hir::VariantData::Struct { .. } => {
872872
self.print_where_clause(generics);
873-
self.print_variant_struct(span, struct_def.fields(), ib, cb)
874-
}
875-
}
876-
}
877-
878-
fn print_variant_struct(
879-
&mut self,
880-
span: rustc_span::Span,
881-
fields: &[hir::FieldDef<'_>],
882-
cb: BoxMarker,
883-
ib: BoxMarker,
884-
) {
885-
self.nbsp();
886-
self.bopen(ib);
887-
self.hardbreak_if_not_bol();
873+
self.nbsp();
874+
self.bopen(ib);
875+
self.hardbreak_if_not_bol();
876+
877+
for field in struct_def.fields() {
878+
self.hardbreak_if_not_bol();
879+
self.maybe_print_comment(field.span.lo());
880+
self.print_attrs_as_outer(self.attrs(field.hir_id));
881+
self.print_ident(field.ident);
882+
self.word_nbsp(":");
883+
self.print_type(field.ty);
884+
self.word(",");
885+
}
888886

889-
for field in fields {
890-
self.hardbreak_if_not_bol();
891-
self.maybe_print_comment(field.span.lo());
892-
self.print_attrs_as_outer(self.attrs(field.hir_id));
893-
self.print_ident(field.ident);
894-
self.word_nbsp(":");
895-
self.print_type(field.ty);
896-
self.word(",");
887+
self.bclose(span, cb)
888+
}
897889
}
898-
899-
self.bclose(span, cb)
900890
}
901891

902892
pub fn print_variant(&mut self, v: &hir::Variant<'_>) {

0 commit comments

Comments
 (0)