diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 3223ca9a731..e7fa81fc87a 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -466,7 +466,7 @@ use rt::io::Decorator; use rt::io::mem::MemWriter; use rt::io; use str; -use sys; +use repr; use util; use vec; @@ -1087,17 +1087,13 @@ impl Poly for T { fn fmt(t: &T, f: &mut Formatter) { match (f.width, f.precision) { (None, None) => { - // XXX: sys::log_str should have a variant which takes a stream - // and we should directly call that (avoids unnecessary - // allocations) - let s = sys::log_str(t); - f.buf.write(s.as_bytes()); + repr::write_repr(f.buf, t); } // If we have a specified width for formatting, then we have to make // this allocation of a new string _ => { - let s = sys::log_str(t); + let s = repr::repr_to_str(t); f.pad(s); } } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 031fd7993eb..a788064293f 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -616,6 +616,16 @@ pub fn write_repr(writer: &mut io::Writer, object: &T) { } } +pub fn repr_to_str(t: &T) -> ~str { + use str; + use rt::io; + use rt::io::Decorator; + + let mut result = io::mem::MemWriter::new(); + write_repr(&mut result as &mut io::Writer, t); + str::from_utf8_owned(result.inner()) +} + #[cfg(test)] struct P {a: int, b: f64} diff --git a/src/libstd/sys.rs b/src/libstd/sys.rs index 0f38671bfc2..d20a6696e27 100644 --- a/src/libstd/sys.rs +++ b/src/libstd/sys.rs @@ -15,18 +15,7 @@ use c_str::ToCStr; use libc::size_t; use libc; -use repr; use rt::task; -use str; - -pub fn log_str(t: &T) -> ~str { - use rt::io; - use rt::io::Decorator; - - let mut result = io::mem::MemWriter::new(); - repr::write_repr(&mut result as &mut io::Writer, t); - str::from_utf8_owned(result.inner()) -} /// Trait for initiating task failure. pub trait FailWithCause { diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index fa13f78d0f9..77dbafa5ad7 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -40,9 +40,10 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt, } // It used to be the case that this deriving implementation invoked -// std::sys::log_str, but this isn't sufficient because it doesn't invoke the -// to_str() method on each field. Hence we mirror the logic of the log_str() -// method, but with tweaks to call to_str() on sub-fields. +// std::repr::repr_to_str, but this isn't sufficient because it +// doesn't invoke the to_str() method on each field. Hence we mirror +// the logic of the repr_to_str() method, but with tweaks to call to_str() +// on sub-fields. fn to_str_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr { let to_str = cx.ident_of("to_str"); diff --git a/src/test/run-pass/fixed_length_vec_glue.rs b/src/test/run-pass/fixed_length_vec_glue.rs index ab34245a8f0..d778844f4d7 100644 --- a/src/test/run-pass/fixed_length_vec_glue.rs +++ b/src/test/run-pass/fixed_length_vec_glue.rs @@ -10,13 +10,13 @@ // xfail-fast: check-fast screws up repr paths -use std::sys; +use std::repr; struct Struc { a: u8, b: [int, ..3], c: int } pub fn main() { let arr = [1,2,3]; let struc = Struc {a: 13u8, b: arr, c: 42}; - let s = sys::log_str(&struc); + let s = repr::repr_to_str(&struc); assert_eq!(s, ~"Struc{a: 13u8, b: [1, 2, 3], c: 42}"); } diff --git a/src/test/run-pass/log-str.rs b/src/test/run-pass/log-str.rs index a8914de917e..8859b533626 100644 --- a/src/test/run-pass/log-str.rs +++ b/src/test/run-pass/log-str.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::sys; +use std::repr; pub fn main() { - let act = sys::log_str(&~[1, 2, 3]); + let act = repr::repr_to_str(&~[1, 2, 3]); assert_eq!(~"~[1, 2, 3]", act); let act = format!("{:?}/{:6?}", ~[1, 2, 3], ~"hi");