Skip to content

Commit 7e4404b

Browse files
committed
auto merge of #9937 : brson/rust/log_str, r=alexcrichton
2 parents 6dd6623 + 3675e42 commit 7e4404b

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

src/libstd/fmt/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ use rt::io::Decorator;
466466
use rt::io::mem::MemWriter;
467467
use rt::io;
468468
use str;
469-
use sys;
469+
use repr;
470470
use util;
471471
use vec;
472472

@@ -1087,17 +1087,13 @@ impl<T> Poly for T {
10871087
fn fmt(t: &T, f: &mut Formatter) {
10881088
match (f.width, f.precision) {
10891089
(None, None) => {
1090-
// XXX: sys::log_str should have a variant which takes a stream
1091-
// and we should directly call that (avoids unnecessary
1092-
// allocations)
1093-
let s = sys::log_str(t);
1094-
f.buf.write(s.as_bytes());
1090+
repr::write_repr(f.buf, t);
10951091
}
10961092

10971093
// If we have a specified width for formatting, then we have to make
10981094
// this allocation of a new string
10991095
_ => {
1100-
let s = sys::log_str(t);
1096+
let s = repr::repr_to_str(t);
11011097
f.pad(s);
11021098
}
11031099
}

src/libstd/repr.rs

+10
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,16 @@ pub fn write_repr<T>(writer: &mut io::Writer, object: &T) {
616616
}
617617
}
618618

619+
pub fn repr_to_str<T>(t: &T) -> ~str {
620+
use str;
621+
use rt::io;
622+
use rt::io::Decorator;
623+
624+
let mut result = io::mem::MemWriter::new();
625+
write_repr(&mut result as &mut io::Writer, t);
626+
str::from_utf8_owned(result.inner())
627+
}
628+
619629
#[cfg(test)]
620630
struct P {a: int, b: f64}
621631

src/libstd/sys.rs

-11
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,7 @@
1515
use c_str::ToCStr;
1616
use libc::size_t;
1717
use libc;
18-
use repr;
1918
use rt::task;
20-
use str;
21-
22-
pub fn log_str<T>(t: &T) -> ~str {
23-
use rt::io;
24-
use rt::io::Decorator;
25-
26-
let mut result = io::mem::MemWriter::new();
27-
repr::write_repr(&mut result as &mut io::Writer, t);
28-
str::from_utf8_owned(result.inner())
29-
}
3019

3120
/// Trait for initiating task failure.
3221
pub trait FailWithCause {

src/libsyntax/ext/deriving/to_str.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt,
4040
}
4141

4242
// It used to be the case that this deriving implementation invoked
43-
// std::sys::log_str, but this isn't sufficient because it doesn't invoke the
44-
// to_str() method on each field. Hence we mirror the logic of the log_str()
45-
// method, but with tweaks to call to_str() on sub-fields.
43+
// std::repr::repr_to_str, but this isn't sufficient because it
44+
// doesn't invoke the to_str() method on each field. Hence we mirror
45+
// the logic of the repr_to_str() method, but with tweaks to call to_str()
46+
// on sub-fields.
4647
fn to_str_substructure(cx: @ExtCtxt, span: Span,
4748
substr: &Substructure) -> @Expr {
4849
let to_str = cx.ident_of("to_str");

src/test/run-pass/fixed_length_vec_glue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
// xfail-fast: check-fast screws up repr paths
1212

13-
use std::sys;
13+
use std::repr;
1414

1515
struct Struc { a: u8, b: [int, ..3], c: int }
1616

1717
pub fn main() {
1818
let arr = [1,2,3];
1919
let struc = Struc {a: 13u8, b: arr, c: 42};
20-
let s = sys::log_str(&struc);
20+
let s = repr::repr_to_str(&struc);
2121
assert_eq!(s, ~"Struc{a: 13u8, b: [1, 2, 3], c: 42}");
2222
}

src/test/run-pass/log-str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::sys;
11+
use std::repr;
1212

1313
pub fn main() {
14-
let act = sys::log_str(&~[1, 2, 3]);
14+
let act = repr::repr_to_str(&~[1, 2, 3]);
1515
assert_eq!(~"~[1, 2, 3]", act);
1616
1717
let act = format!("{:?}/{:6?}", ~[1, 2, 3], ~"hi");

0 commit comments

Comments
 (0)