File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ use print::pp::Breaks::{Consistent, Inconsistent};
28
28
use ptr:: P ;
29
29
use std_inject;
30
30
31
- use std:: { ascii, mem } ;
31
+ use std:: ascii;
32
32
use std:: io:: { self , Write , Read } ;
33
33
use std:: iter;
34
34
@@ -187,18 +187,13 @@ impl<'a> State<'a> {
187
187
pub fn to_string < F > ( f : F ) -> String where
188
188
F : FnOnce ( & mut State ) -> io:: Result < ( ) > ,
189
189
{
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 ( )
202
197
}
203
198
204
199
pub fn binop_to_string ( op : BinOpToken ) -> & ' static str {
You can’t perform that action at this time.
0 commit comments