about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-12-27 14:28:54 -0800
committerPatrick Walton <pcwalton@mimiga.net>2014-01-03 14:01:58 -0800
commit497b63ddf044e43173f83110a4ffb4c61413c524 (patch)
treedba90beb6f4f2aaf09df0c7fbbc4f3c4e046cff4 /src/libsyntax
parentb26018cc89681d979555f3405df71e370941ffd5 (diff)
downloadrust-497b63ddf044e43173f83110a4ffb4c61413c524.tar.gz
rust-497b63ddf044e43173f83110a4ffb4c61413c524.zip
librustc: De-`@mut` all writers
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/print/pp.rs4
-rw-r--r--src/libsyntax/print/pprust.rs45
2 files changed, 35 insertions, 14 deletions
diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs
index ad55d64494b..5afe6266c99 100644
--- a/src/libsyntax/print/pp.rs
+++ b/src/libsyntax/print/pp.rs
@@ -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
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 7cf47cc1fd4..5a529120b07 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -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> {