syntax: Remove use of TraitObject in pretty printer

This commit is contained in:
Erick Tryzelaar 2015-04-16 19:54:05 -07:00
parent cfb9d286ea
commit e3dd68d0a4

View File

@ -28,7 +28,7 @@
use ptr::P;
use std_inject;
use std::{ascii, mem};
use std::ascii;
use std::io::{self, Write, Read};
use std::iter;
@ -187,18 +187,13 @@ pub fn new(cm: &'a CodeMap,
pub fn to_string<F>(f: F) -> String where
F: FnOnce(&mut State) -> io::Result<()>,
{
use std::raw::TraitObject;
let mut s = rust_printer(Box::new(Vec::new()));
f(&mut s).unwrap();
eof(&mut s.s).unwrap();
let wr = unsafe {
// FIXME(pcwalton): A nasty function to extract the string from an `Write`
// that we "know" to be a `Vec<u8>` that works around the lack of checked
// downcasts.
let obj: &TraitObject = mem::transmute(&s.s.out);
mem::transmute::<*mut (), &Vec<u8>>(obj.data)
};
String::from_utf8(wr.clone()).unwrap()
let mut wr = Vec::new();
{
let mut printer = rust_printer(Box::new(&mut wr));
f(&mut printer).unwrap();
eof(&mut printer.s).unwrap();
}
String::from_utf8(wr).unwrap()
}
pub fn binop_to_string(op: BinOpToken) -> &'static str {