Skip to content

Commit

Permalink
syntax: Remove use of TraitObject in pretty printer
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Apr 21, 2015
1 parent cfb9d28 commit e3dd68d
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/libsyntax/print/pprust.rs
Expand Up @@ -28,7 +28,7 @@ use print::pp::Breaks::{Consistent, Inconsistent};
use ptr::P;
use std_inject;

use std::{ascii, mem};
use std::ascii;
use std::io::{self, Write, Read};
use std::iter;

Expand Down Expand Up @@ -187,18 +187,13 @@ impl<'a> State<'a> {
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 {
Expand Down

0 comments on commit e3dd68d

Please sign in to comment.