mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Rename Printer constructor from mk_printer() to Printer::new()
This commit is contained in:
parent
de9b573eed
commit
953da9832d
@ -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,
|
||||
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
@ -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)
|
||||
|
@ -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,
|
||||
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user