Skip to content

Commit

Permalink
Rename Printer constructor from mk_printer() to Printer::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 15, 2022
1 parent de9b573 commit 953da98
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
46 changes: 23 additions & 23 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,6 @@ struct PrintStackElem {

const SIZE_INFINITY: isize = 0xffff;

pub fn mk_printer() -> Printer {
let linewidth = 78;
// Yes 55, it makes the ring buffers big enough to never fall behind.
let n: usize = 55 * linewidth;
debug!("mk_printer {}", linewidth);
Printer {
out: String::new(),
buf_max_len: n,
margin: linewidth as isize,
space: linewidth as isize,
left: 0,
right: 0,
// Initialize a single entry; advance_right() will extend it on demand
// up to `buf_max_len` elements.
buf: vec![BufEntry::default()],
left_total: 0,
right_total: 0,
scan_stack: VecDeque::new(),
print_stack: Vec::new(),
pending_indentation: 0,
}
}

pub struct Printer {
out: String,
buf_max_len: usize,
Expand Down Expand Up @@ -288,6 +265,29 @@ impl Default for BufEntry {
}

impl Printer {
pub fn new() -> Self {
let linewidth = 78;
// Yes 55, it makes the ring buffers big enough to never fall behind.
let n: usize = 55 * linewidth;
debug!("Printer::new {}", linewidth);
Printer {
out: String::new(),
buf_max_len: n,
margin: linewidth as isize,
space: linewidth as isize,
left: 0,
right: 0,
// Initialize a single entry; advance_right() will extend it on demand
// up to `buf_max_len` elements.
buf: vec![BufEntry::default()],
left_total: 0,
right_total: 0,
scan_stack: VecDeque::new(),
print_stack: Vec::new(),
pending_indentation: 0,
}
}

pub fn last_token(&self) -> Token {
self.buf[self.right].token.clone()
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn print_crate<'a>(
edition: Edition,
) -> String {
let mut s =
State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann };
State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann };

if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
// We need to print `#![no_std]` (and its feature gate) so that
Expand Down Expand Up @@ -910,7 +910,7 @@ impl<'a> PrintState<'a> for State<'a> {

impl<'a> State<'a> {
pub fn new() -> State<'a> {
State { s: pp::mk_printer(), comments: None, ann: &NoAnn }
State { s: pp::Printer::new(), comments: None, ann: &NoAnn }
}

crate fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'a> State<'a> {
ann: &'a dyn PpAnn,
) -> State<'a> {
State {
s: pp::mk_printer(),
s: pp::Printer::new(),
comments: Some(Comments::new(sm, filename, input)),
attrs,
ann,
Expand All @@ -186,7 +186,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
where
F: FnOnce(&mut State<'_>),
{
let mut printer = State { s: pp::mk_printer(), comments: None, attrs: &|_| &[], ann };
let mut printer = State { s: pp::Printer::new(), comments: None, attrs: &|_| &[], ann };
f(&mut printer);
printer.s.eof()
}
Expand Down

0 comments on commit 953da98

Please sign in to comment.