about summary refs log tree commit diff
path: root/src/test/compile-fail/use-after-move-implicity-coerced-object.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-02-19 18:56:33 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-02-23 20:51:56 -0800
commitb78b749810f4ed53e8287adfb284f9f32f16b73c (patch)
tree0894e97a61d0ab09dd42d73202aeefca175463eb /src/test/compile-fail/use-after-move-implicity-coerced-object.rs
parent7cc6b5e0a3a2038d66301906f76cdb778304a3bd (diff)
downloadrust-b78b749810f4ed53e8287adfb284f9f32f16b73c.tar.gz
rust-b78b749810f4ed53e8287adfb284f9f32f16b73c.zip
Remove all ToStr impls, add Show impls
This commit changes the ToStr trait to:

    impl<T: fmt::Show> ToStr for T {
        fn to_str(&self) -> ~str { format!("{}", *self) }
    }

The ToStr trait has been on the chopping block for quite awhile now, and this is
the final nail in its coffin. The trait and the corresponding method are not
being removed as part of this commit, but rather any implementations of the
`ToStr` trait are being forbidden because of the generic impl. The new way to
get the `to_str()` method to work is to implement `fmt::Show`.

Formatting into a `&mut Writer` (as `format!` does) is much more efficient than
`ToStr` when building up large strings. The `ToStr` trait forces many
intermediate allocations to be made while the `fmt::Show` trait allows
incremental buildup in the same heap allocated buffer. Additionally, the
`fmt::Show` trait is much more extensible in terms of interoperation with other
`Writer` instances and in more situations. By design the `ToStr` trait requires
at least one allocation whereas the `fmt::Show` trait does not require any
allocations.

Closes #8242
Closes #9806
Diffstat (limited to 'src/test/compile-fail/use-after-move-implicity-coerced-object.rs')
-rw-r--r--src/test/compile-fail/use-after-move-implicity-coerced-object.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/test/compile-fail/use-after-move-implicity-coerced-object.rs b/src/test/compile-fail/use-after-move-implicity-coerced-object.rs
index 537da535457..085ed5db6df 100644
--- a/src/test/compile-fail/use-after-move-implicity-coerced-object.rs
+++ b/src/test/compile-fail/use-after-move-implicity-coerced-object.rs
@@ -10,13 +10,15 @@
 
 // ignore-tidy-linelength
 
+use std::fmt;
+
 struct Number {
     n: i64
 }
 
-impl ToStr for Number {
-    fn to_str(&self) -> ~str {
-        self.n.to_str()
+impl fmt::Show for Number {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f.buf, "{}", self.n)
     }
 }