auto merge of #15493 : brson/rust/tostr, r=pcwalton

This updates https://github.com/rust-lang/rust/pull/15075.

Rename `ToStr::to_str` to `ToString::to_string`. The naive renaming ends up with two `to_string` functions defined on strings in the prelude (the other defined via `collections::str::StrAllocating`). To remedy this I removed `StrAllocating::to_string`, making all conversions from `&str` to `String` go through `Show`. This has a measurable impact on the speed of this conversion, but the sense I get from others is that it's best to go ahead and unify `to_string` and address performance for all `to_string` conversions in `core::fmt`. `String::from_str(...)` still works as a manual fast-path.

Note that the patch was done with a script, and ended up renaming a number of other `*_to_str` functions, particularly inside of rustc. All the ones I saw looked correct, and I didn't notice any additional API breakage.

Closes #15046.
This commit is contained in:
bors 2014-07-08 20:06:40 +00:00
commit 8bb34a3146
208 changed files with 1557 additions and 1390 deletions

View file

@ -90,11 +90,11 @@ impl Results {
let mut set = f();
timed(&mut self.sequential_strings, || {
for i in range(0u, num_keys) {
set.insert(i.to_str());
set.insert(i.to_string());
}
for i in range(0u, num_keys) {
assert!(set.contains(&i.to_str()));
assert!(set.contains(&i.to_string()));
}
})
}
@ -103,7 +103,7 @@ impl Results {
let mut set = f();
timed(&mut self.random_strings, || {
for _ in range(0, num_keys) {
let s = rng.gen::<uint>().to_str();
let s = rng.gen::<uint>().to_string();
set.insert(s);
}
})
@ -112,11 +112,11 @@ impl Results {
{
let mut set = f();
for i in range(0u, num_keys) {
set.insert(i.to_str());
set.insert(i.to_string());
}
timed(&mut self.delete_strings, || {
for i in range(0u, num_keys) {
assert!(set.remove(&i.to_str()));
assert!(set.remove(&i.to_string()));
}
})
}

View file

@ -24,7 +24,7 @@ fn main() {
let n = from_str::<uint>(args.get(1).as_slice()).unwrap();
for i in range(0u, n) {
let x = i.to_str();
let x = i.to_string();
println!("{}", x);
}
}

View file

@ -48,7 +48,7 @@ fn show_color_list(set: Vec<Color>) -> String {
let mut out = String::new();
for col in set.iter() {
out.push_char(' ');
out.push_str(col.to_str().as_slice());
out.push_str(col.to_string().as_slice());
}
out
}

View file

@ -64,7 +64,7 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> String {
k.as_slice()
.to_ascii()
.to_upper()
.into_str(), v).as_slice());
.into_string(), v).as_slice());
}
return buffer
@ -72,7 +72,7 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> String {
// given a map, search for the frequency of a pattern
fn find(mm: &HashMap<Vec<u8> , uint>, key: String) -> uint {
let key = key.to_owned().into_ascii().as_slice().to_lower().into_str();
let key = key.to_owned().into_ascii().as_slice().to_lower().into_string();
match mm.find_equiv(&key.as_bytes()) {
option::None => { return 0u; }
option::Some(&num) => { return num; }

View file

@ -115,7 +115,7 @@ fn main() {
let elapsed = stop - start;
println!("{}\t{}\t{}", n, fibn, elapsed.to_str());
println!("{}\t{}\t{}", n, fibn, elapsed.to_string());
}
}
}

View file

@ -67,7 +67,7 @@ fn main() {
} else {
box io::stdin() as Box<io::Reader>
};
let mut seq = rdr.read_to_str().unwrap();
let mut seq = rdr.read_to_string().unwrap();
let ilen = seq.len();
seq = regex!(">[^\n]*\n|\n").replace_all(seq.as_slice(), NoExpand(""));
@ -109,7 +109,7 @@ fn main() {
let (mut variant_strs, mut counts) = (vec!(), vec!());
for variant in variants.move_iter() {
let seq_arc_copy = seq_arc.clone();
variant_strs.push(variant.to_str().to_owned());
variant_strs.push(variant.to_string().to_owned());
counts.push(Future::spawn(proc() {
count_matches(seq_arc_copy.as_slice(), &variant)
}));

View file

@ -16,18 +16,18 @@
struct t(Box<t>); //~ ERROR this type cannot be instantiated
trait to_str_2 {
fn my_to_str() -> String;
fn my_to_string() -> String;
}
// I use an impl here because it will cause
// the compiler to attempt autoderef and then
// try to resolve the method.
impl to_str_2 for t {
fn my_to_str() -> String { "t".to_string() }
fn my_to_string() -> String { "t".to_string() }
}
fn new_t(x: t) {
x.my_to_str(); //~ ERROR does not implement
x.my_to_string(); //~ ERROR does not implement
}
fn main() {

View file

@ -13,17 +13,17 @@ struct Point {
y: f64,
}
trait NewTrait {
fn a(&self) -> String;
trait ToString_ {
fn to_string(&self) -> String;
}
impl NewTrait for Point {
impl ToString_ for Point {
fn new(x: f64, y: f64) -> Point {
//~^ ERROR method `new` is not a member of trait `NewTrait`
//~^ ERROR method `new` is not a member of trait `ToString_`
Point { x: x, y: y }
}
fn a(&self) -> String {
fn to_string(&self) -> String {
format!("({}, {})", self.x, self.y)
}
}
@ -32,5 +32,5 @@ fn main() {
let p = Point::new(0.0, 0.0);
//~^ ERROR unresolved name `Point::new`
//~^^ ERROR failed to resolve. Use of undeclared module `Point`
println!("{}", p.a());
println!("{}", p.to_string());
}

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-linelength
#![allow(dead_code)]
#![deny(uppercase_variables)]
@ -30,7 +32,7 @@ fn main() {
let mut buff = [0u8, ..16];
match f.read(buff) {
Ok(cnt) => println!("read this many bytes: {}", cnt),
Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {}", EndOfFile.to_str()),
Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {}", EndOfFile.to_string()),
//~^ ERROR variable names should start with a lowercase character
}

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-linelength
struct S {
x: Box<E>
@ -29,7 +30,7 @@ fn main() {
f(&s, |hellothere| {
match hellothere.x { //~ ERROR cannot move out
box Foo(_) => {}
box Bar(x) => println!("{}", x.to_str()), //~ NOTE attempting to move value to here
box Bar(x) => println!("{}", x.to_string()), //~ NOTE attempting to move value to here
box Baz => {}
}
})

View file

@ -12,7 +12,7 @@ struct S {
y: int
}
impl Cmp, ToStr for S { //~ ERROR: expected `{` but found `,`
impl Cmp, ToString for S { //~ ERROR: expected `{` but found `,`
fn eq(&&other: S) { false }
fn to_str(&self) -> String { "hi".to_string() }
fn to_string(&self) -> String { "hi".to_string() }
}

View file

@ -21,7 +21,7 @@ mod foo {
impl Add for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Clone for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Iterator for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl ToStr for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl ToString for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Writer for Test {} //~ ERROR: attempt to implement a nonexistent trait
fn foo() {
@ -33,7 +33,7 @@ mod foo {
impl Add for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Clone for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Iterator for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl ToStr for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl ToString for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Writer for Test {} //~ ERROR: attempt to implement a nonexistent trait
fn foo() {
@ -48,7 +48,7 @@ fn qux() {
impl Add for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Clone for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Iterator for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl ToStr for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl ToString for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Writer for Test {} //~ ERROR: attempt to implement a nonexistent trait
fn foo() {

View file

@ -20,7 +20,7 @@ struct Test;
impl Add for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Clone for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Iterator for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl ToStr for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl ToString for Test {} //~ ERROR: attempt to implement a nonexistent trait
impl Writer for Test {} //~ ERROR: attempt to implement a nonexistent trait
fn main() {

View file

@ -11,7 +11,7 @@
enum E {}
fn f(e: E) {
println!("{}", (e as int).to_str()); //~ ERROR non-scalar cast
println!("{}", (e as int).to_string()); //~ ERROR non-scalar cast
}
fn main() {}

View file

@ -23,10 +23,10 @@ impl fmt::Show for Number {
}
struct List {
list: Vec<Box<ToStr>> }
list: Vec<Box<ToString>> }
impl List {
fn push(&mut self, n: Box<ToStr>) {
fn push(&mut self, n: Box<ToString>) {
self.list.push(n);
}
}
@ -35,6 +35,6 @@ fn main() {
let n = box Number { n: 42 };
let mut l = box List { list: Vec::new() };
l.push(n);
let x = n.to_str();
let x = n.to_string();
//~^ ERROR: use of moved value: `n`
}

View file

@ -21,4 +21,4 @@ pub fn p() -> C {
C
}
fn main() { }
fn main() { }

View file

@ -49,9 +49,9 @@ fn main() {
assert_eq!(!true, false);
assert_eq!(!false, true);
let s = false.to_str();
let s = false.to_string();
assert_eq!(s.as_slice(), "false");
let s = true.to_str();
let s = true.to_string();
assert_eq!(s.as_slice(), "true");
assert!(true > false);

View file

@ -45,7 +45,7 @@ fn main() {
debug!("debug");
info!("info");
});
let s = r.read_to_str().unwrap();
let s = r.read_to_string().unwrap();
assert!(s.as_slice().contains("info"));
assert!(!s.as_slice().contains("debug"));
}

View file

@ -11,16 +11,16 @@
// aux-build:cci_class_cast.rs
extern crate cci_class_cast;
use std::to_str::ToStr;
use std::to_str::ToString;
use cci_class_cast::kitty::cat;
fn print_out(thing: Box<ToStr>, expected: String) {
let actual = thing.to_str();
fn print_out(thing: Box<ToString>, expected: String) {
let actual = thing.to_string();
println!("{}", actual);
assert_eq!(actual.to_string(), expected);
}
pub fn main() {
let nyan: Box<ToStr> = box cat(0u, 2, "nyan".to_string()) as Box<ToStr>;
let nyan: Box<ToString> = box cat(0u, 2, "nyan".to_string()) as Box<ToString>;
print_out(nyan, "nyan".to_string());
}

View file

@ -57,13 +57,13 @@ impl fmt::Show for cat {
}
}
fn print_out(thing: Box<ToStr>, expected: String) {
let actual = thing.to_str();
fn print_out(thing: Box<ToString>, expected: String) {
let actual = thing.to_string();
println!("{}", actual);
assert_eq!(actual.to_string(), expected);
}
pub fn main() {
let nyan: Box<ToStr> = box cat(0u, 2, "nyan".to_string()) as Box<ToStr>;
let nyan: Box<ToString> = box cat(0u, 2, "nyan".to_string()) as Box<ToString>;
print_out(nyan, "nyan".to_string());
}

View file

@ -41,15 +41,15 @@ impl fmt::Show for Custom {
}
pub fn main() {
assert_eq!(B1.to_str(), "B1".to_string());
assert_eq!(B2.to_str(), "B2".to_string());
assert_eq!(C1(3).to_str(), "C1(3)".to_string());
assert_eq!(C2(B2).to_str(), "C2(B2)".to_string());
assert_eq!(D1{ a: 2 }.to_str(), "D1 { a: 2 }".to_string());
assert_eq!(E.to_str(), "E".to_string());
assert_eq!(F(3).to_str(), "F(3)".to_string());
assert_eq!(G(3, 4).to_str(), "G(3, 4)".to_string());
assert_eq!(G(3, 4).to_str(), "G(3, 4)".to_string());
assert_eq!(I{ a: 2, b: 4 }.to_str(), "I { a: 2, b: 4 }".to_string());
assert_eq!(J(Custom).to_str(), "J(yay)".to_string());
assert_eq!(B1.to_string(), "B1".to_string());
assert_eq!(B2.to_string(), "B2".to_string());
assert_eq!(C1(3).to_string(), "C1(3)".to_string());
assert_eq!(C2(B2).to_string(), "C2(B2)".to_string());
assert_eq!(D1{ a: 2 }.to_string(), "D1 { a: 2 }".to_string());
assert_eq!(E.to_string(), "E".to_string());
assert_eq!(F(3).to_string(), "F(3)".to_string());
assert_eq!(G(3, 4).to_string(), "G(3, 4)".to_string());
assert_eq!(G(3, 4).to_string(), "G(3, 4)".to_string());
assert_eq!(I{ a: 2, b: 4 }.to_string(), "I { a: 2, b: 4 }".to_string());
assert_eq!(J(Custom).to_string(), "J(yay)".to_string());
}

View file

@ -11,24 +11,24 @@
#![feature(macro_rules)]
use s = std::num::strconv;
use to_str = std::num::strconv::float_to_str_common;
use to_string = std::num::strconv::float_to_str_common;
macro_rules! t(($a:expr, $b:expr) => { { let (r, _) = $a; assert_eq!(r, $b.to_string()) } })
pub fn main() {
// Basic usage
t!(to_str(1.2345678e-5f64, 10u, true, s::SignNeg, s::DigMax(6), s::ExpDec, false),
t!(to_string(1.2345678e-5f64, 10u, true, s::SignNeg, s::DigMax(6), s::ExpDec, false),
"1.234568e-5")
// Hexadecimal output
t!(to_str(7.281738281250e+01f64, 16u, true, s::SignAll, s::DigMax(6), s::ExpBin, false),
t!(to_string(7.281738281250e+01f64, 16u, true, s::SignAll, s::DigMax(6), s::ExpBin, false),
"+1.2345p+6")
t!(to_str(-1.777768135071e-02f64, 16u, true, s::SignAll, s::DigMax(6), s::ExpBin, false),
t!(to_string(-1.777768135071e-02f64, 16u, true, s::SignAll, s::DigMax(6), s::ExpBin, false),
"-1.2345p-6")
// Some denormals
t!(to_str(4.9406564584124654e-324f64, 10u, true, s::SignNeg, s::DigMax(6), s::ExpBin, false),
t!(to_string(4.9406564584124654e-324f64, 10u, true, s::SignNeg, s::DigMax(6), s::ExpBin, false),
"1p-1074")
t!(to_str(2.2250738585072009e-308f64, 10u, true, s::SignNeg, s::DigMax(6), s::ExpBin, false),
t!(to_string(2.2250738585072009e-308f64, 10u, true, s::SignNeg, s::DigMax(6), s::ExpBin, false),
"1p-1022")
}

View file

@ -17,6 +17,6 @@ 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 = repr::repr_to_str(&struc);
let s = repr::repr_to_string(&struc);
assert_eq!(s, "Struc{a: 13u8, b: [1, 2, 3], c: 42}".to_string());
}

View file

@ -79,8 +79,8 @@ fn read_board_grid<rdr:'static + io::Reader>(mut input: rdr)
mod test {
#[test]
pub fn trivial_to_str() {
assert!(lambda.to_str() == "\\")
pub fn trivial_to_string() {
assert!(lambda.to_string() == "\\")
}
}

View file

@ -10,7 +10,7 @@
enum what { }
fn what_to_str(x: what) -> String
fn what_to_string(x: what) -> String
{
match x {
}

View file

@ -24,6 +24,6 @@ pub fn main() {
let mut table = HashMap::new();
table.insert("one".to_string(), 1i);
table.insert("two".to_string(), 2i);
assert!(check_strs(table.to_str().as_slice(), "{one: 1, two: 2}") ||
check_strs(table.to_str().as_slice(), "{two: 2, one: 1}"));
assert!(check_strs(table.to_string().as_slice(), "{one: 1, two: 2}") ||
check_strs(table.to_string().as_slice(), "{two: 2, one: 1}"));
}

View file

@ -94,7 +94,7 @@ impl AsciiArt {
}
}
// Allows AsciiArt to be converted to a string using the libcore ToStr trait.
// Allows AsciiArt to be converted to a string using the libcore ToString trait.
// Note that the %s fmt! specifier will not call this automatically.
impl fmt::Show for AsciiArt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -159,7 +159,7 @@ pub fn check_strs(actual: &str, expected: &str) -> bool {
fn test_ascii_art_ctor() {
let art = AsciiArt(3, 3, '*');
assert!(check_strs(art.to_str().as_slice(), "...\n...\n..."));
assert!(check_strs(art.to_string().as_slice(), "...\n...\n..."));
}
@ -168,7 +168,7 @@ fn test_add_pt() {
art.add_pt(0, 0);
art.add_pt(0, -10);
art.add_pt(1, 2);
assert!(check_strs(art.to_str().as_slice(), "*..\n...\n.*."));
assert!(check_strs(art.to_string().as_slice(), "*..\n...\n.*."));
}
@ -176,7 +176,7 @@ fn test_shapes() {
let mut art = AsciiArt(4, 4, '*');
art.add_rect(Rect {top_left: Point {x: 0, y: 0}, size: Size {width: 4, height: 4}});
art.add_point(Point {x: 2, y: 2});
assert!(check_strs(art.to_str().as_slice(), "****\n*..*\n*.**\n****"));
assert!(check_strs(art.to_string().as_slice(), "****\n*..*\n*.**\n****"));
}
pub fn main() {

View file

@ -11,11 +11,11 @@
pub fn main() {
trait Text {
fn to_str(&self) -> String;
fn to_string(&self) -> String;
}
fn to_string(t: Box<Text>) {
println!("{}", t.to_str());
println!("{}", t.to_string());
}
}

View file

@ -96,19 +96,19 @@ priv fn parse_response(io: @io::Reader) -> Result {
}
}
priv fn cmd_to_str(cmd: ~[String]) -> String {
priv fn cmd_to_string(cmd: ~[String]) -> String {
let mut res = "*".to_string();
res.push_str(cmd.len().to_str());
res.push_str(cmd.len().to_string());
res.push_str("\r\n");
for s in cmd.iter() {
res.push_str(["$".to_string(), s.len().to_str(), "\r\n".to_string(),
res.push_str(["$".to_string(), s.len().to_string(), "\r\n".to_string(),
(*s).clone(), "\r\n".to_string()].concat() );
}
res
}
fn query(cmd: ~[String], sb: TcpSocketBuf) -> Result {
let cmd = cmd_to_str(cmd);
let cmd = cmd_to_string(cmd);
//println!("{}", cmd);
sb.write_str(cmd);
let res = parse_response(@sb as @io::Reader);
@ -116,7 +116,7 @@ fn query(cmd: ~[String], sb: TcpSocketBuf) -> Result {
}
fn query2(cmd: ~[String]) -> Result {
let _cmd = cmd_to_str(cmd);
let _cmd = cmd_to_string(cmd);
io::with_str_reader("$3\r\nXXX\r\n".to_string())(|sb| {
let res = parse_response(@sb as @io::Reader);
println!("{:?}", res);

View file

@ -11,15 +11,15 @@
type FontTableTag = u32;
trait FontTableTagConversions {
fn tag_to_str(self);
fn tag_to_string(self);
}
impl FontTableTagConversions for FontTableTag {
fn tag_to_str(self) {
fn tag_to_string(self) {
&self;
}
}
pub fn main() {
5.tag_to_str();
5.tag_to_string();
}

View file

@ -38,7 +38,7 @@ impl<A> option_monad<A> for Option<A> {
}
fn transform(x: Option<int>) -> Option<String> {
x.bind(|n| Some(*n + 1) ).bind(|n| Some(n.to_str()) )
x.bind(|n| Some(*n + 1) ).bind(|n| Some(n.to_string()) )
}
pub fn main() {

View file

@ -20,7 +20,7 @@ impl StringBuffer {
}
}
fn to_str(sb: StringBuffer) -> String {
fn to_string(sb: StringBuffer) -> String {
sb.s
}
@ -30,6 +30,6 @@ pub fn main() {
};
sb.append("Hello, ");
sb.append("World!");
let str = to_str(sb);
let str = to_string(sb);
assert_eq!(str.as_slice(), "Hello, World!");
}

View file

@ -32,6 +32,6 @@ impl<T:fmt::Show> fmt::Show for PolymorphicThingy<T> {
}
pub fn main() {
println!("{}", Thingy { x: 1, y: 2 }.to_str());
println!("{}", PolymorphicThingy { x: Thingy { x: 1, y: 2 } }.to_str());
println!("{}", Thingy { x: 1, y: 2 }.to_string());
println!("{}", PolymorphicThingy { x: Thingy { x: 1, y: 2 } }.to_string());
}

View file

@ -72,7 +72,7 @@ pub fn main() {
// N.B. This is required because method lookup hasn't been performed so
// we don't know whether the called method takes mutable self, before
// the dereference itself is type-checked (a chicken-and-egg problem).
(*n).to_str();
(*n).to_string();
assert_eq!(n.counts(), (2, 4));
// Mutable deref used for calling a method taking &mut self.

View file

@ -12,7 +12,7 @@ extern crate collections;
use std::collections::{ Map, MutableMap};
use std::str::{SendStr, Owned, Slice};
use std::to_str::ToStr;
use std::to_str::ToString;
use self::collections::TreeMap;
use std::option::Some;

View file

@ -31,7 +31,7 @@ trait uint_utils {
impl uint_utils for uint {
fn str(&self) -> String {
self.to_str()
self.to_string()
}
fn multi(&self, f: |uint|) {
let mut c = 0u;

View file

@ -21,6 +21,6 @@ fn main() {
});
assert!(res.is_err());
let output = reader.read_to_str().unwrap();
let output = reader.read_to_string().unwrap();
assert!(output.as_slice().contains("Hello, world!"));
}

View file

@ -54,7 +54,7 @@ macro_rules! iotest (
iotest!(fn eventual_timeout() {
use native;
let addr = next_test_ip4();
let host = addr.ip.to_str();
let host = addr.ip.to_string();
let port = addr.port;
// Use a native task to receive connections because it turns out libuv is
@ -82,7 +82,7 @@ iotest!(fn eventual_timeout() {
iotest!(fn timeout_success() {
let addr = next_test_ip4();
let host = addr.ip.to_str();
let host = addr.ip.to_string();
let port = addr.port;
let _l = TcpListener::bind(host.as_slice(), port).unwrap().listen();

View file

@ -61,7 +61,7 @@ fn main() {
for _ in range(0u, 1000) {
let tx = tx.clone();
TaskBuilder::new().stack_size(64 * 1024).spawn(proc() {
let host = addr.ip.to_str();
let host = addr.ip.to_string();
let port = addr.port;
match TcpStream::connect(host.as_slice(), port) {
Ok(stream) => {

View file

@ -27,10 +27,10 @@ fn checktests() {
let tests = __test::TESTS;
assert!(
tests.iter().any(|t| t.desc.name.to_str().as_slice() == "shouldignore" &&
tests.iter().any(|t| t.desc.name.to_string().as_slice() == "shouldignore" &&
t.desc.ignore));
assert!(
tests.iter().any(|t| t.desc.name.to_str().as_slice() == "shouldnotignore" &&
tests.iter().any(|t| t.desc.name.to_string().as_slice() == "shouldnotignore" &&
!t.desc.ignore));
}

View file

@ -39,7 +39,7 @@ impl<T:to_str> to_str for Option<T> {
impl to_str for int {
fn to_str_(&self) -> String {
self.to_str()
self.to_string()
}
}

View file

@ -11,16 +11,16 @@
trait to_str {
fn to_string(&self) -> String;
fn to_string_(&self) -> String;
}
impl to_str for int {
fn to_string(&self) -> String { self.to_str() }
fn to_string_(&self) -> String { self.to_string() }
}
impl to_str for String {
fn to_string(&self) -> String { self.clone() }
fn to_string_(&self) -> String { self.clone() }
}
impl to_str for () {
fn to_string(&self) -> String { "()".to_string() }
fn to_string_(&self) -> String { "()".to_string() }
}
trait map<T> {
@ -40,7 +40,7 @@ fn foo<U, T: map<U>>(x: T) -> Vec<String> {
x.map(|_e| "hi".to_string() )
}
fn bar<U:to_str,T:map<U>>(x: T) -> Vec<String> {
x.map(|_e| _e.to_string() )
x.map(|_e| _e.to_string_() )
}
pub fn main() {

View file

@ -11,29 +11,29 @@
trait to_str {
fn to_string(&self) -> String;
fn to_string_(&self) -> String;
}
impl to_str for int {
fn to_string(&self) -> String { self.to_str() }
fn to_string_(&self) -> String { self.to_string() }
}
impl<T:to_str> to_str for Vec<T> {
fn to_string(&self) -> String {
fn to_string_(&self) -> String {
format!("[{}]",
self.iter()
.map(|e| e.to_string())
.map(|e| e.to_string_())
.collect::<Vec<String>>()
.connect(", "))
}
}
pub fn main() {
assert!(1.to_string() == "1".to_string());
assert!((vec!(2i, 3, 4)).to_string() == "[2, 3, 4]".to_string());
assert!(1.to_string_() == "1".to_string());
assert!((vec!(2i, 3, 4)).to_string_() == "[2, 3, 4]".to_string());
fn indirect<T:to_str>(x: T) -> String {
format!("{}!", x.to_string())
format!("{}!", x.to_string_())
}
assert!(indirect(vec!(10i, 20)) == "[10, 20]!".to_string());

View file

@ -9,12 +9,12 @@
// except according to those terms.
pub fn main() {
assert_eq!((vec!(0i, 1)).to_str(), "[0, 1]".to_string());
assert_eq!((&[1i, 2]).to_str(), "[1, 2]".to_string());
assert_eq!((vec!(0i, 1)).to_string(), "[0, 1]".to_string());
assert_eq!((&[1i, 2]).to_string(), "[1, 2]".to_string());
let foo = vec!(3i, 4);
let bar = &[4i, 5];
assert_eq!(foo.to_str(), "[3, 4]".to_string());
assert_eq!(bar.to_str(), "[4, 5]".to_string());
assert_eq!(foo.to_string(), "[3, 4]".to_string());
assert_eq!(bar.to_string(), "[4, 5]".to_string());
}