Skip to content

Commit 48fd838

Browse files
Replace pretty-printer Box<dyn Write> with &mut Vec<u8>
1 parent 38de9bc commit 48fd838

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/librustc/hir/print.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::hir::{GenericParam, GenericParamKind, GenericArg};
1717

1818
use std::borrow::Cow;
1919
use std::cell::Cell;
20-
use std::io::{self, Write, Read};
20+
use std::io::{self, Read};
2121
use std::vec;
2222

2323
pub enum AnnNode<'a> {
@@ -112,7 +112,7 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
112112
krate: &hir::Crate,
113113
filename: FileName,
114114
input: &mut dyn Read,
115-
out: Box<dyn Write + 'a>,
115+
out: &'a mut Vec<u8>,
116116
ann: &'a dyn PpAnn)
117117
-> io::Result<()> {
118118
let mut s = State::new_from_input(cm, sess, filename, input, out, ann);
@@ -130,15 +130,15 @@ impl<'a> State<'a> {
130130
sess: &ParseSess,
131131
filename: FileName,
132132
input: &mut dyn Read,
133-
out: Box<dyn Write + 'a>,
133+
out: &'a mut Vec<u8>,
134134
ann: &'a dyn PpAnn)
135135
-> State<'a> {
136136
let comments = comments::gather_comments(sess, filename, input);
137137
State::new(cm, out, ann, Some(comments))
138138
}
139139

140140
pub fn new(cm: &'a SourceMap,
141-
out: Box<dyn Write + 'a>,
141+
out: &'a mut Vec<u8>,
142142
ann: &'a dyn PpAnn,
143143
comments: Option<Vec<comments::Comment>>)
144144
-> State<'a> {
@@ -159,7 +159,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
159159
let mut wr = Vec::new();
160160
{
161161
let mut printer = State {
162-
s: pp::mk_printer(Box::new(&mut wr), default_columns),
162+
s: pp::mk_printer(&mut wr, default_columns),
163163
cm: None,
164164
comments: None,
165165
cur_cmnt: 0,

src/librustc_driver/pretty.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ pub fn print_after_parsing(sess: &Session,
733733

734734
if let PpmSource(s) = ppm {
735735
// Silently ignores an identified node.
736-
let out: &mut dyn Write = &mut out;
736+
let out = &mut out;
737737
s.call_with_pp_support(sess, None, move |annotation| {
738738
debug!("pretty printing source code {:?}", s);
739739
let sess = annotation.sess();
@@ -742,7 +742,7 @@ pub fn print_after_parsing(sess: &Session,
742742
krate,
743743
src_name,
744744
&mut rdr,
745-
box out,
745+
out,
746746
annotation.pp_ann(),
747747
false)
748748
}).unwrap()
@@ -779,7 +779,7 @@ pub fn print_after_hir_lowering<'tcx>(
779779
match (ppm, opt_uii) {
780780
(PpmSource(s), _) => {
781781
// Silently ignores an identified node.
782-
let out: &mut dyn Write = &mut out;
782+
let out = &mut out;
783783
s.call_with_pp_support(tcx.sess, Some(tcx), move |annotation| {
784784
debug!("pretty printing source code {:?}", s);
785785
let sess = annotation.sess();
@@ -788,14 +788,14 @@ pub fn print_after_hir_lowering<'tcx>(
788788
krate,
789789
src_name,
790790
&mut rdr,
791-
box out,
791+
out,
792792
annotation.pp_ann(),
793793
true)
794794
})
795795
}
796796

797797
(PpmHir(s), None) => {
798-
let out: &mut dyn Write = &mut out;
798+
let out = &mut out;
799799
s.call_with_pp_support_hir(tcx, move |annotation, krate| {
800800
debug!("pretty printing source code {:?}", s);
801801
let sess = annotation.sess();
@@ -804,21 +804,21 @@ pub fn print_after_hir_lowering<'tcx>(
804804
krate,
805805
src_name,
806806
&mut rdr,
807-
box out,
807+
out,
808808
annotation.pp_ann())
809809
})
810810
}
811811

812812
(PpmHirTree(s), None) => {
813-
let out: &mut dyn Write = &mut out;
813+
let out = &mut out;
814814
s.call_with_pp_support_hir(tcx, move |_annotation, krate| {
815815
debug!("pretty printing source code {:?}", s);
816816
write!(out, "{:#?}", krate)
817817
})
818818
}
819819

820820
(PpmHir(s), Some(uii)) => {
821-
let out: &mut dyn Write = &mut out;
821+
let out = &mut out;
822822
s.call_with_pp_support_hir(tcx, move |annotation, _| {
823823
debug!("pretty printing source code {:?}", s);
824824
let sess = annotation.sess();
@@ -827,7 +827,7 @@ pub fn print_after_hir_lowering<'tcx>(
827827
&sess.parse_sess,
828828
src_name,
829829
&mut rdr,
830-
box out,
830+
out,
831831
annotation.pp_ann());
832832
for node_id in uii.all_matching_node_ids(hir_map) {
833833
let hir_id = tcx.hir().node_to_hir_id(node_id);

src/libsyntax/print/pp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
137137
use std::collections::VecDeque;
138138
use std::fmt;
139-
use std::io;
139+
use std::io::{self, Write};
140140
use std::borrow::Cow;
141141
use log::debug;
142142

@@ -236,7 +236,7 @@ crate struct PrintStackElem {
236236

237237
const SIZE_INFINITY: isize = 0xffff;
238238

239-
pub fn mk_printer<'a>(out: Box<dyn io::Write+'a>, linewidth: usize) -> Printer<'a> {
239+
pub fn mk_printer(out: &mut Vec<u8>, linewidth: usize) -> Printer<'_> {
240240
// Yes 55, it makes the ring buffers big enough to never fall behind.
241241
let n: usize = 55 * linewidth;
242242
debug!("mk_printer {}", linewidth);
@@ -259,7 +259,7 @@ pub fn mk_printer<'a>(out: Box<dyn io::Write+'a>, linewidth: usize) -> Printer<'
259259
}
260260

261261
pub struct Printer<'a> {
262-
out: Box<dyn io::Write+'a>,
262+
out: &'a mut Vec<u8>,
263263
buf_max_len: usize,
264264
/// Width of lines we're constrained to
265265
margin: isize,

src/libsyntax/print/pprust.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use syntax_pos::{self, BytePos};
2121
use syntax_pos::{DUMMY_SP, FileName};
2222

2323
use std::borrow::Cow;
24-
use std::io::{self, Write, Read};
24+
use std::io::{self, Read};
2525
use std::vec;
2626

2727
pub enum AnnNode<'a> {
@@ -54,7 +54,7 @@ pub struct State<'a> {
5454
is_expanded: bool
5555
}
5656

57-
fn rust_printer<'a>(writer: Box<dyn Write+'a>, ann: &'a dyn PpAnn) -> State<'a> {
57+
fn rust_printer<'a>(writer: &'a mut Vec<u8>, ann: &'a dyn PpAnn) -> State<'a> {
5858
State {
5959
s: pp::mk_printer(writer, DEFAULT_COLUMNS),
6060
cm: None,
@@ -77,7 +77,7 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
7777
krate: &ast::Crate,
7878
filename: FileName,
7979
input: &mut dyn Read,
80-
out: Box<dyn Write+'a>,
80+
out: &mut Vec<u8>,
8181
ann: &'a dyn PpAnn,
8282
is_expanded: bool) -> io::Result<()> {
8383
let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded);
@@ -111,15 +111,15 @@ impl<'a> State<'a> {
111111
sess: &ParseSess,
112112
filename: FileName,
113113
input: &mut dyn Read,
114-
out: Box<dyn Write+'a>,
114+
out: &'a mut Vec<u8>,
115115
ann: &'a dyn PpAnn,
116116
is_expanded: bool) -> State<'a> {
117117
let comments = comments::gather_comments(sess, filename, input);
118118
State::new(cm, out, ann, Some(comments), is_expanded)
119119
}
120120

121121
pub fn new(cm: &'a SourceMap,
122-
out: Box<dyn Write+'a>,
122+
out: &'a mut Vec<u8>,
123123
ann: &'a dyn PpAnn,
124124
comments: Option<Vec<comments::Comment>>,
125125
is_expanded: bool) -> State<'a> {
@@ -141,7 +141,7 @@ pub fn to_string<F>(f: F) -> String where
141141
let mut wr = Vec::new();
142142
{
143143
let ann = NoAnn;
144-
let mut printer = rust_printer(Box::new(&mut wr), &ann);
144+
let mut printer = rust_printer(&mut wr, &ann);
145145
f(&mut printer).unwrap();
146146
printer.s.eof().unwrap();
147147
}

0 commit comments

Comments
 (0)