Skip to content

Commit 73e781e

Browse files
committed
syntax: Remove use of TraitObject in pretty printer
1 parent 1ad2128 commit 73e781e

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use print::pp::Breaks::{Consistent, Inconsistent};
2828
use ptr::P;
2929
use std_inject;
3030

31-
use std::{ascii, mem};
31+
use std::ascii;
3232
use std::io::{self, Write, Read};
3333
use std::iter;
3434

@@ -187,18 +187,13 @@ impl<'a> State<'a> {
187187
pub fn to_string<F>(f: F) -> String where
188188
F: FnOnce(&mut State) -> io::Result<()>,
189189
{
190-
use std::raw::TraitObject;
191-
let mut s = rust_printer(Box::new(Vec::new()));
192-
f(&mut s).unwrap();
193-
eof(&mut s.s).unwrap();
194-
let wr = unsafe {
195-
// FIXME(pcwalton): A nasty function to extract the string from an `Write`
196-
// that we "know" to be a `Vec<u8>` that works around the lack of checked
197-
// downcasts.
198-
let obj: &TraitObject = mem::transmute(&s.s.out);
199-
mem::transmute::<*mut (), &Vec<u8>>(obj.data)
200-
};
201-
String::from_utf8(wr.clone()).unwrap()
190+
let mut wr = Vec::new();
191+
{
192+
let mut printer = rust_printer(Box::new(&mut wr));
193+
f(&mut printer).unwrap();
194+
eof(&mut printer.s).unwrap();
195+
}
196+
String::from_utf8(wr).unwrap()
202197
}
203198

204199
pub fn binop_to_string(op: BinOpToken) -> &'static str {

0 commit comments

Comments
 (0)