librustc: De-`@mut` all writers

This commit is contained in:
Patrick Walton 2013-12-27 14:28:54 -08:00
parent b26018cc89
commit 497b63ddf0
4 changed files with 38 additions and 17 deletions

View File

@ -600,7 +600,7 @@ pub fn pretty_print_input(sess: Session,
&crate,
source_name(input),
rdr as @mut io::Reader,
@mut stdout as @mut io::Writer,
~stdout as ~io::Writer,
annotation,
is_expanded);
}

View File

@ -347,12 +347,12 @@ impl<O:DataFlowOperator+Clone+'static> DataFlowContext<O> {
debug!("Dataflow result:");
debug!("{}", {
let this = @(*self).clone();
this.pretty_print_to(@mut io::stderr() as @mut io::Writer, blk);
this.pretty_print_to(~io::stderr() as ~io::Writer, blk);
""
});
}
fn pretty_print_to(@self, wr: @mut io::Writer, blk: &ast::Block) {
fn pretty_print_to(@self, wr: ~io::Writer, blk: &ast::Block) {
let mut ps = pprust::rust_printer_annotated(wr,
self.tcx.sess.intr(),
self as @pprust::pp_ann);

View File

@ -148,7 +148,7 @@ pub struct print_stack_elt {
pub static size_infinity: int = 0xffff;
pub fn mk_printer(out: @mut io::Writer, linewidth: uint) -> Printer {
pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer {
// Yes 3, it makes the ring buffers big enough to never
// fall behind.
let n: uint = 3 * linewidth;
@ -255,7 +255,7 @@ pub fn mk_printer(out: @mut io::Writer, linewidth: uint) -> Printer {
* called 'print'.
*/
pub struct Printer {
out: @mut io::Writer,
out: ~io::Writer,
buf_len: uint,
margin: int, // width of lines we're constrained to
space: int, // number of spaces left on line

View File

@ -27,6 +27,7 @@ use print::pp::{breaks, consistent, inconsistent, eof};
use print::pp;
use print::pprust;
use std::cast;
use std::char;
use std::str;
use std::io;
@ -86,11 +87,11 @@ pub fn end(s: &mut ps) {
pp::end(&mut s.s);
}
pub fn rust_printer(writer: @mut io::Writer, intr: @ident_interner) -> ps {
pub fn rust_printer(writer: ~io::Writer, intr: @ident_interner) -> ps {
return rust_printer_annotated(writer, intr, @no_ann::new() as @pp_ann);
}
pub fn rust_printer_annotated(writer: @mut io::Writer,
pub fn rust_printer_annotated(writer: ~io::Writer,
intr: @ident_interner,
ann: @pp_ann)
-> ps {
@ -122,7 +123,7 @@ pub fn print_crate(cm: @CodeMap,
crate: &ast::Crate,
filename: @str,
input: @mut io::Reader,
out: @mut io::Writer,
out: ~io::Writer,
ann: @pp_ann,
is_expanded: bool) {
let (cmnts, lits) = comments::gather_comments_and_literals(
@ -203,26 +204,40 @@ pub fn path_to_str(p: &ast::Path, intr: @ident_interner) -> ~str {
pub fn fun_to_str(decl: &ast::fn_decl, purity: ast::purity, name: ast::Ident,
opt_explicit_self: Option<ast::explicit_self_>,
generics: &ast::Generics, intr: @ident_interner) -> ~str {
let wr = @mut MemWriter::new();
let mut s = rust_printer(wr as @mut io::Writer, intr);
let wr = ~MemWriter::new();
let mut s = rust_printer(wr as ~io::Writer, intr);
print_fn(&mut s, decl, Some(purity), AbiSet::Rust(),
name, generics, opt_explicit_self, ast::inherited);
end(&mut s); // Close the head box
end(&mut s); // Close the outer box
eof(&mut s.s);
str::from_utf8_owned(wr.inner_ref().to_owned())
// XXX(pcwalton): Need checked downcasts.
unsafe {
let (_, wr): (uint, ~MemWriter) = cast::transmute(s.s.out);
let result = str::from_utf8_owned(wr.inner_ref().to_owned());
cast::forget(wr);
result
}
}
pub fn block_to_str(blk: &ast::Block, intr: @ident_interner) -> ~str {
let wr = @mut MemWriter::new();
let mut s = rust_printer(wr as @mut io::Writer, intr);
let wr = ~MemWriter::new();
let mut s = rust_printer(wr as ~io::Writer, intr);
// containing cbox, will be closed by print-block at }
cbox(&mut s, indent_unit);
// head-ibox, will be closed by print-block after {
ibox(&mut s, 0u);
print_block(&mut s, blk);
eof(&mut s.s);
str::from_utf8_owned(wr.inner_ref().to_owned())
// XXX(pcwalton): Need checked downcasts.
unsafe {
let (_, wr): (uint, ~MemWriter) = cast::transmute(s.s.out);
let result = str::from_utf8_owned(wr.inner_ref().to_owned());
cast::forget(wr);
result
}
}
pub fn meta_item_to_str(mi: &ast::MetaItem, intr: @ident_interner) -> ~str {
@ -2304,11 +2319,17 @@ pub fn print_string(s: &mut ps, st: &str, style: ast::StrStyle) {
}
pub fn to_str<T>(t: &T, f: |&mut ps, &T|, intr: @ident_interner) -> ~str {
let wr = @mut MemWriter::new();
let mut s = rust_printer(wr as @mut io::Writer, intr);
let wr = ~MemWriter::new();
let mut s = rust_printer(wr as ~io::Writer, intr);
f(&mut s, t);
eof(&mut s.s);
str::from_utf8_owned(wr.inner_ref().to_owned())
// XXX(pcwalton): Need checked downcasts.
unsafe {
let (_, wr): (uint, ~MemWriter) = cast::transmute(s.s.out);
let result = str::from_utf8_owned(wr.inner_ref().to_owned());
cast::forget(wr);
result
}
}
pub fn next_comment(s: &mut ps) -> Option<comments::cmnt> {