Skip to content

Commit 953da98

Browse files
committed
Rename Printer constructor from mk_printer() to Printer::new()
1 parent de9b573 commit 953da98

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

compiler/rustc_ast_pretty/src/pp.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -222,29 +222,6 @@ struct PrintStackElem {
222222

223223
const SIZE_INFINITY: isize = 0xffff;
224224

225-
pub fn mk_printer() -> Printer {
226-
let linewidth = 78;
227-
// Yes 55, it makes the ring buffers big enough to never fall behind.
228-
let n: usize = 55 * linewidth;
229-
debug!("mk_printer {}", linewidth);
230-
Printer {
231-
out: String::new(),
232-
buf_max_len: n,
233-
margin: linewidth as isize,
234-
space: linewidth as isize,
235-
left: 0,
236-
right: 0,
237-
// Initialize a single entry; advance_right() will extend it on demand
238-
// up to `buf_max_len` elements.
239-
buf: vec![BufEntry::default()],
240-
left_total: 0,
241-
right_total: 0,
242-
scan_stack: VecDeque::new(),
243-
print_stack: Vec::new(),
244-
pending_indentation: 0,
245-
}
246-
}
247-
248225
pub struct Printer {
249226
out: String,
250227
buf_max_len: usize,
@@ -288,6 +265,29 @@ impl Default for BufEntry {
288265
}
289266

290267
impl Printer {
268+
pub fn new() -> Self {
269+
let linewidth = 78;
270+
// Yes 55, it makes the ring buffers big enough to never fall behind.
271+
let n: usize = 55 * linewidth;
272+
debug!("Printer::new {}", linewidth);
273+
Printer {
274+
out: String::new(),
275+
buf_max_len: n,
276+
margin: linewidth as isize,
277+
space: linewidth as isize,
278+
left: 0,
279+
right: 0,
280+
// Initialize a single entry; advance_right() will extend it on demand
281+
// up to `buf_max_len` elements.
282+
buf: vec![BufEntry::default()],
283+
left_total: 0,
284+
right_total: 0,
285+
scan_stack: VecDeque::new(),
286+
print_stack: Vec::new(),
287+
pending_indentation: 0,
288+
}
289+
}
290+
291291
pub fn last_token(&self) -> Token {
292292
self.buf[self.right].token.clone()
293293
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn print_crate<'a>(
103103
edition: Edition,
104104
) -> String {
105105
let mut s =
106-
State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann };
106+
State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann };
107107

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

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

916916
crate fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)

compiler/rustc_hir_pretty/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'a> State<'a> {
170170
ann: &'a dyn PpAnn,
171171
) -> State<'a> {
172172
State {
173-
s: pp::mk_printer(),
173+
s: pp::Printer::new(),
174174
comments: Some(Comments::new(sm, filename, input)),
175175
attrs,
176176
ann,
@@ -186,7 +186,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
186186
where
187187
F: FnOnce(&mut State<'_>),
188188
{
189-
let mut printer = State { s: pp::mk_printer(), comments: None, attrs: &|_| &[], ann };
189+
let mut printer = State { s: pp::Printer::new(), comments: None, attrs: &|_| &[], ann };
190190
f(&mut printer);
191191
printer.s.eof()
192192
}

0 commit comments

Comments
 (0)